//============================================================================*
        // OnQuantityChanged()
        //============================================================================*

        private void OnQuantityChanged(object sender, EventArgs e)
        {
            if (!m_fInitialized || m_fPopulating)
            {
                return;
            }

            double dQuantity = QuantityTextBox.Value;

            m_Transaction.Quantity = dQuantity;

            m_fChanged = true;

            if (m_Transaction.TransactionType == cTransaction.eTransactionType.ReduceStock || m_Transaction.TransactionType == cTransaction.eTransactionType.Fired)
            {
                double dCost = m_DataFiles.SupplyCostEach(m_Transaction.Supply);

                if (m_Transaction.Supply.SupplyType == cSupply.eSupplyTypes.Powder)
                {
                    dCost = cDataFiles.StandardToMetric(dCost * 7000.0, cDataFiles.eDataType.CanWeight);
                }

                m_Transaction.Cost = dCost * m_Transaction.Quantity;

                CostTextBox.Value  = m_Transaction.Cost;
                TotalTextBox.Value = m_Transaction.Cost;
            }

            SetAvgCost();

            UpdateButtons();
        }
Esempio n. 2
0
        //============================================================================*
        // SetAmmoData()
        //============================================================================*

        public void SetAmmoData(ListViewItem Item, cAmmo Ammo)
        {
            Item.SubItems.Clear();

            Item.Text = Ammo.Manufacturer != null?Ammo.Manufacturer.ToString() : "Reloads";

            Item.Group   = Groups[(int)Ammo.FirearmType];
            Item.Tag     = Ammo;
            Item.Checked = Ammo.Checked;

            Item.SubItems.Add(Ammo.PartNumber);
            Item.SubItems.Add(Ammo.Type);
            Item.SubItems.Add(Ammo.Reload ? "Y" : "");

            if (Ammo.FirearmType != cFirearm.eFireArmType.Shotgun)
            {
                Item.SubItems.Add(Ammo.TestList.Count > 0 ? "Y" : "");
            }

            cCaliber.CurrentFirearmType = Ammo.Caliber.FirearmType;
            Item.SubItems.Add(Ammo.Caliber.ToString());

            Item.SubItems.Add(String.Format(m_strBulletWeightFormat, cDataFiles.StandardToMetric(Ammo.BulletWeight, m_eFirearmType != cFirearm.eFireArmType.Shotgun ? cDataFiles.eDataType.BulletWeight : cDataFiles.eDataType.ShotWeight)));
            Item.SubItems.Add(String.Format(m_strDimensionFormat, cDataFiles.StandardToMetric(Ammo.BulletDiameter, cDataFiles.eDataType.Dimension)));
            Item.SubItems.Add(Ammo.BallisticCoefficient > 0.0 ? String.Format("{0:F3}", Ammo.BallisticCoefficient) : "-");

            if (Ammo.FirearmType != cFirearm.eFireArmType.Shotgun)
            {
                Item.SubItems.Add(String.Format("{0:F3}", cBullet.CalculateSectionalDensity(Ammo.BulletDiameter, Ammo.BulletWeight)));
            }

            Item.SubItems.Add(Ammo.MinimumStockLevel != 0 ? String.Format("{0:N0}", Ammo.MinimumStockLevel) : "-");

            double dCost = 0.0;

            if (m_DataFiles.Preferences.TrackInventory)
            {
                Item.SubItems.Add(Ammo.QuantityOnHand != 0.0 ? String.Format("{0:N0}", Ammo.QuantityOnHand) : "-");

                dCost = Ammo.QuantityOnHand * m_DataFiles.SupplyCostEach(Ammo);
            }
            else
            {
                Item.SubItems.Add(Ammo.Quantity != 0.0 ? String.Format("{0:N0}", Ammo.Quantity) : "-");

                dCost = Ammo.Cost;
            }

            Item.SubItems.Add(dCost != 0.0 ? String.Format("{0:F2}", dCost) : "-");
        }
Esempio n. 3
0
        //============================================================================*
        // SetCostEach()
        //============================================================================*

        private void SetCostEach()
        {
            double dCostEach = (QuantityTextBox.Value > 0.0 ? CostTextBox.Value / QuantityTextBox.Value : 0.0);

            if (m_DataFiles.Preferences.TrackInventory)
            {
                dCostEach = m_DataFiles.SupplyCostEach(m_Powder) * cDataFiles.StandardToMetric(7000.0, cDataFiles.eDataType.CanWeight);
            }

            CostLbLabel.Text = String.Format("Cost/{0}:", cDataFiles.MetricString(cDataFiles.eDataType.CanWeight));

            CostEachLabel.Text = String.Format("{0}{1:F2}", m_DataFiles.Preferences.Currency, dCostEach);

            CanWeightLabel.Text = String.Format("{0}{1}", cDataFiles.MetricString(cDataFiles.eDataType.CanWeight), QuantityTextBox.Value != 1.0 ? "s" : "");
        }
Esempio n. 4
0
        //============================================================================*
        // SetCostEach()
        //============================================================================*

        private void SetCostEach()
        {
            CostEachLabel.Text = String.Format("{0}{1:F2}", m_DataFiles.Preferences.Currency, m_DataFiles.SupplyCostEach(m_Case));
        }
Esempio n. 5
0
        //============================================================================*
        // SetTransactionData()
        //============================================================================*

        public void SetTransactionData(ListViewItem Item, cTransaction Transaction)
        {
            Item.SubItems.Clear();

            if (Transaction.TransactionType == cTransaction.eTransactionType.SetStockLevel)
            {
                Item.Text = "";
            }
            else
            {
                Item.Text = Transaction.Date.ToShortDateString();
            }

            if (Transaction.Archived)
            {
                Item.Text += " - Archived";
            }

            Item.Checked = Transaction.Checked;

            Item.Tag = Transaction;

            if (Transaction.TransactionType == cTransaction.eTransactionType.SetStockLevel)
            {
                Transaction.Source = "";
            }

            if (Transaction.BatchID != 0)
            {
                Transaction.Source = String.Format("Batch {0:G0}", Transaction.BatchID);
            }

            Item.SubItems.Add(cTransaction.TransactionDescriptionString(Transaction.TransactionType));
            Item.SubItems.Add(Transaction.Source);

            double dQuantity = Transaction.Quantity;

            switch (Transaction.Supply.SupplyType)
            {
            case cSupply.eSupplyTypes.Ammo:
            case cSupply.eSupplyTypes.Bullets:
            case cSupply.eSupplyTypes.Cases:
            case cSupply.eSupplyTypes.Primers:
                Item.SubItems.Add(String.Format("{0:N0}", dQuantity));
                break;

            case cSupply.eSupplyTypes.Powder:
                dQuantity = cDataFiles.StandardToMetric(dQuantity / 7000.0, cDataFiles.eDataType.CanWeight);

                Item.SubItems.Add(String.Format("{0:F3}", dQuantity));

                break;
            }

            double dCostEach = m_DataFiles.SupplyCostEach(Transaction.Supply);

            double dCost = 0.0;

            if (Transaction.BatchID != 0)
            {
                if (Transaction.Supply.SupplyType == cSupply.eSupplyTypes.Ammo)
                {
                    dCost = m_DataFiles.BatchCost(Transaction.BatchID);
                }
                else
                {
                    dCost = Transaction.Quantity * dCostEach;
                }
            }
            else
            {
                dCost = Transaction.Cost;
            }

            Item.SubItems.Add(String.Format("{0:F2}", dCost));

            if (Transaction.BatchID == 0 &&
                (Transaction.TransactionType == cTransaction.eTransactionType.Purchase ||
                 Transaction.TransactionType == cTransaction.eTransactionType.SetStockLevel))
            {
                Item.SubItems.Add(Transaction.Tax != 0.0 ? String.Format("{0:F2}", Transaction.Tax) : "-");
                Item.SubItems.Add(Transaction.Shipping != 0.0 ? String.Format("{0:F2}", Transaction.Shipping) : "-");
            }
            else
            {
                Item.SubItems.Add("-");
                Item.SubItems.Add("-");
            }

            Item.SubItems.Add(String.Format("{0:F2}", dCost + Transaction.Tax + Transaction.Shipping));

            if (Transaction.TransactionType == cTransaction.eTransactionType.Purchase ||
                Transaction.TransactionType == cTransaction.eTransactionType.SetStockLevel)
            {
                if (m_DataFiles.Preferences.IncludeTaxShipping)
                {
                    dCost += (Transaction.Tax + Transaction.Shipping);
                }

                dCostEach = 0.0;

                if (dQuantity > 0.0)
                {
                    dCostEach = dCost / dQuantity;
                }

                Item.SubItems.Add(String.Format("{0:F2}", dCostEach));
            }
            else
            {
                Item.SubItems.Add("-");
            }
        }
Esempio n. 6
0
        //============================================================================*
        // PopulateInventoryData()
        //============================================================================*

        private void PopulateInventoryData()
        {
            ComponentLabel.Text = String.Format("{0} {1}", m_Supply.ToString(), cSupply.SupplyTypeString(m_Supply));

            double dQuantityOnHand   = m_Supply.QuantityOnHand;
            double dValue            = m_DataFiles.SupplyCost(m_Supply);
            double dCostEach         = m_DataFiles.SupplyCostEach(m_Supply);
            double dLastPurchaseQty  = m_Supply.LastPurchaseQty;
            double dTotalPurchaseQty = m_Supply.TotalPurchaseQty;
            double dTotalAdjustQty   = m_Supply.TotalAdjustQty;
            double dTotalUsedQty     = m_Supply.TotalUsedQty;

            if (m_Supply.SupplyType == cSupply.eSupplyTypes.Powder)
            {
                dQuantityOnHand   = cDataFiles.StandardToMetric(m_Supply.QuantityOnHand / 7000.0, cDataFiles.eDataType.CanWeight);
                dCostEach         = cDataFiles.StandardToMetric(m_DataFiles.SupplyCostEach(m_Supply) * 7000.0, cDataFiles.eDataType.CanWeight);
                dLastPurchaseQty  = cDataFiles.StandardToMetric(m_Supply.LastPurchaseQty / 7000.0, cDataFiles.eDataType.CanWeight);
                dTotalPurchaseQty = cDataFiles.StandardToMetric(m_Supply.TotalPurchaseQty / 7000.0, cDataFiles.eDataType.CanWeight);
                dTotalAdjustQty   = cDataFiles.StandardToMetric(m_Supply.TotalAdjustQty / 7000.0, cDataFiles.eDataType.CanWeight);
                dTotalUsedQty     = cDataFiles.StandardToMetric(m_Supply.TotalUsedQty / 7000.0, cDataFiles.eDataType.CanWeight);

                string strQtyformat = "{0:F3} {1}{2}";

                QuantityLabel.Text        = String.Format(strQtyformat, dQuantityOnHand, (m_DataFiles.Preferences.MetricCanWeights ? "kilo" : "lb"), (dQuantityOnHand != 1.0 ? "s" : ""));
                LastPurchaseQtyLabel.Text = String.Format(strQtyformat, dLastPurchaseQty, (m_DataFiles.Preferences.MetricCanWeights ? "kilo" : "lb"), (dLastPurchaseQty != 1.0 ? "s" : ""));
                TotalPurchasedLabel.Text  = String.Format(strQtyformat, dTotalPurchaseQty, (m_DataFiles.Preferences.MetricCanWeights ? "kilo" : "lb"), (dTotalPurchaseQty != 1.0 ? "s" : ""));

                TotalAdjustLabel.Text = String.Format(strQtyformat, dTotalAdjustQty, (m_DataFiles.Preferences.MetricCanWeights ? "kilo" : "lb"), (dTotalAdjustQty != 1.0 ? "s" : ""));
                TotalUsedLabel.Text   = String.Format(strQtyformat, dTotalUsedQty, (m_DataFiles.Preferences.MetricCanWeights ? "kilo" : "lb"), (dTotalUsedQty != 1.0 ? "s" : ""));
            }
            else
            {
                string strQtyformat = "{0:G0}";

                QuantityLabel.Text        = String.Format(strQtyformat, dQuantityOnHand);
                LastPurchaseQtyLabel.Text = String.Format(strQtyformat, dLastPurchaseQty);
                TotalPurchasedLabel.Text  = String.Format(strQtyformat, dTotalPurchaseQty);

                TotalAdjustLabel.Text = String.Format(strQtyformat, dTotalAdjustQty);
                TotalUsedLabel.Text   = String.Format(strQtyformat, dTotalUsedQty);
            }

            ValueLabel.Text    = String.Format("{0}{1:F2} *", m_DataFiles.Preferences.Currency, dValue);
            CostEachLabel.Text = String.Format("{0}{1:F2} *", m_DataFiles.Preferences.Currency, dCostEach);

            LastPurchaseDateLabel.Text = (m_Supply.LastPurchaseDate.Year > 2009 ? m_Supply.LastPurchaseDate.ToShortDateString() : "N/A");
            LastPurchaseCostLabel.Text = String.Format("{0}{1:F2}", m_DataFiles.Preferences.Currency, m_Supply.LastPurchaseCost);

            TotalCostLabel.Text = String.Format("{0}{1:F2}", m_DataFiles.Preferences.Currency, m_Supply.TotalPurchaseCost);

            if (m_Supply.SupplyType == cSupply.eSupplyTypes.Powder)
            {
                MinimumStockLevelTextBox.Value            = cDataFiles.StandardToMetric(m_Supply.MinimumStockLevel, cDataFiles.eDataType.CanWeight) / (m_DataFiles.Preferences.MetricCanWeights ? 1000.0 :  7000.0);
                MinimumStockLevelMeasurementLabel.Visible = true;
                cDataFiles.SetMetricLabel(MinimumStockLevelMeasurementLabel, cDataFiles.eDataType.CanWeight);
            }
            else
            {
                MinimumStockLevelTextBox.Value            = m_Supply.MinimumStockLevel;
                MinimumStockLevelMeasurementLabel.Visible = false;
            }

            MinimumStockLevelTextBox.NumDecimals = m_Supply.SupplyType == cSupply.eSupplyTypes.Powder ? 3 : 0;

            if (m_DataFiles.Preferences.AverageCosts)
            {
                MethodLabel.Text = "* - Values based on avg of all purchases";
            }
            else
            {
                MethodLabel.Text = "* - Values based on last purchase only";
            }

            if (m_DataFiles.Preferences.IncludeTaxShipping)
            {
                MethodLabel.Text += " including tax && shipping";
            }
        }
Esempio n. 7
0
        //============================================================================*
        // OnPrintPage()
        //============================================================================*

        private void OnPrintPage(object sender, PrintPageEventArgs e)
        {
            //----------------------------------------------------------------------------*
            // Create the fonts
            //----------------------------------------------------------------------------*

            Font HeaderFont = new Font("Trebuchet MS", 8, FontStyle.Bold);
            Font DataFont   = new Font("Trebuchet MS", 8, FontStyle.Regular);

            //----------------------------------------------------------------------------*
            // Calculate Column Header Name Widths
            //----------------------------------------------------------------------------*

            string strText;
            SizeF  TextSize;

            foreach (cPrintColumn PrintColumn in m_AmmoColumns)
            {
                TextSize = e.Graphics.MeasureString(PrintColumn.Name, HeaderFont);

                if (TextSize.Width > PrintColumn.Width)
                {
                    PrintColumn.Width = TextSize.Width;
                }
            }

            //----------------------------------------------------------------------------*
            // Calculate Header Widths for Supplies
            //----------------------------------------------------------------------------*

            foreach (cAmmo Ammo in m_AmmoList)
            {
                cCaliber.CurrentFirearmType = Ammo.FirearmType;

                //----------------------------------------------------------------------------*
                // Manufacturer
                //----------------------------------------------------------------------------*

                TextSize = e.Graphics.MeasureString(Ammo.Manufacturer.ToString(), DataFont);

                if (TextSize.Width > m_AmmoColumns[0].Width)
                {
                    m_AmmoColumns[0].Width = TextSize.Width;
                }

                //----------------------------------------------------------------------------*
                // Part Number
                //----------------------------------------------------------------------------*

                TextSize = e.Graphics.MeasureString(Ammo.PartNumber, DataFont);

                if (TextSize.Width > m_AmmoColumns[1].Width)
                {
                    m_AmmoColumns[1].Width = TextSize.Width;
                }

                //----------------------------------------------------------------------------*
                // Model/Type
                //----------------------------------------------------------------------------*

                TextSize = e.Graphics.MeasureString(Ammo.Type, DataFont);

                if (TextSize.Width > m_AmmoColumns[2].Width)
                {
                    m_AmmoColumns[2].Width = TextSize.Width;
                }

                //----------------------------------------------------------------------------*
                // Caliber
                //----------------------------------------------------------------------------*

                TextSize = e.Graphics.MeasureString(Ammo.Caliber.ToString(), DataFont);

                if (TextSize.Width > m_AmmoColumns[4].Width)
                {
                    m_AmmoColumns[4].Width = TextSize.Width;
                }

                //----------------------------------------------------------------------------*
                // Cost
                //----------------------------------------------------------------------------*

                TextSize = e.Graphics.MeasureString("99999.99", DataFont);

                if (TextSize.Width > m_AmmoColumns[7].Width)
                {
                    m_AmmoColumns[7].Width = TextSize.Width;
                }
            }

            float nLineWidth = 0;

            foreach (cPrintColumn PrintColumn in m_AmmoColumns)
            {
                nLineWidth += PrintColumn.Width;
            }

            nLineWidth += ((m_AmmoColumns.Length - 1) * 10.0f);

            float nLeftMargin = (e.PageBounds.Width / 2) - (nLineWidth / 2.0f);

            //----------------------------------------------------------------------------*
            // Prepare for printing
            //----------------------------------------------------------------------------*

            Rectangle PageRect = e.PageBounds;

            int nXDPI = (int)((double)PageRect.Width / 8.5);
            int nYDPI = (int)((double)PageRect.Height / 11);

            PageRect.X     += (int)((double)nXDPI * 0.5);
            PageRect.Width -= ((int)((double)nXDPI * 0.5) * 2);

            PageRect.Y      += (int)((double)nYDPI * 0.5);
            PageRect.Height -= ((int)((double)nYDPI * 0.5) * 2);

            float nY = PageRect.Top;
            float nX = nLeftMargin;

            bool fPageHeader = false;

            //----------------------------------------------------------------------------*
            // Loop through the ammo in the list
            //----------------------------------------------------------------------------*

            float nQtyX  = 0;
            float nCostX = 0;

            bool fHeader = false;

            foreach (cAmmo Ammo in m_AmmoList)
            {
                if (nY > PageRect.Bottom)
                {
                    e.HasMorePages = true;

                    return;
                }

                //----------------------------------------------------------------------------*
                // If this Ammo has already been printed, skip
                // to the next Ammo in the list
                //----------------------------------------------------------------------------*

                if (Ammo.Printed)
                {
                    continue;
                }

                Ammo.Printed = true;

                cCaliber.CurrentFirearmType = Ammo.FirearmType;

                //----------------------------------------------------------------------------*
                // Draw the page header if needed
                //----------------------------------------------------------------------------*

                if (!fPageHeader)
                {
                    //----------------------------------------------------------------------------*
                    // Draw the Title
                    //----------------------------------------------------------------------------*

                    nY = cPrintObject.PrintReportTitle(m_DataFiles.Preferences.AmmoMinStockFilter ? "Ammunition Shopping List" : "Ammunition List", e, PageRect);

                    if (m_DataFiles.Preferences.TrackInventory)
                    {
                        strText = m_DataFiles.CostText;

                        TextSize = e.Graphics.MeasureString(strText, HeaderFont);

                        e.Graphics.DrawString(strText, HeaderFont, Brushes.Black, e.MarginBounds.Left + (e.MarginBounds.Width / 2) - (TextSize.Width / 2), nY);

                        nY += TextSize.Height;
                    }

                    nY += HeaderFont.Height;

                    fPageHeader = true;
                    fHeader     = false;
                }

                //----------------------------------------------------------------------------*
                // Draw the header if needed
                //----------------------------------------------------------------------------*

                if (!fHeader)
                {
                    //----------------------------------------------------------------------------*
                    // Loop through the headers
                    //----------------------------------------------------------------------------*

                    nX = nLeftMargin;

                    foreach (cPrintColumn PrintColumn in m_AmmoColumns)
                    {
                        if (PrintColumn.Name.Substring(0, 4) == "Cost")
                        {
                            TextSize = e.Graphics.MeasureString(PrintColumn.Name, HeaderFont);

                            e.Graphics.DrawString(PrintColumn.Name, HeaderFont, Brushes.Black, nX + PrintColumn.Width - TextSize.Width, nY);
                        }
                        else
                        {
                            e.Graphics.DrawString(PrintColumn.Name, HeaderFont, Brushes.Black, nX, nY);
                        }

                        nX += (PrintColumn.Width + 10);
                    }

                    nX -= 10;

                    TextSize = e.Graphics.MeasureString(m_AmmoColumns[0].Name, HeaderFont);

                    nY += TextSize.Height;

                    e.Graphics.DrawLine(Pens.Black, nLeftMargin, nY, nX, nY);

                    nX = nLeftMargin;

                    fHeader = true;
                }

                //----------------------------------------------------------------------------*
                // Draw the Ammo info
                //----------------------------------------------------------------------------*

                // Manufacturer

                strText = Ammo.Manufacturer.ToString();

                nX = nLeftMargin;

                e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX, nY);

                nX += (m_AmmoColumns[0].Width + 10);

                // Part Number

                strText = String.Format("{0}", Ammo.PartNumber);

                TextSize = e.Graphics.MeasureString(strText, DataFont);

                e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX, nY);

                nX += (m_AmmoColumns[1].Width + 10);

                // Model/Type

                strText = String.Format("{0}", Ammo.Type);

                TextSize = e.Graphics.MeasureString(strText, DataFont);

                e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX, nY);

                nX += (m_AmmoColumns[2].Width + 10);

                // Reload?

                if (Ammo.Reload)
                {
                    strText = "Yes";

                    TextSize = e.Graphics.MeasureString(strText, DataFont);

                    e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + (m_AmmoColumns[3].Width / 2) - (TextSize.Width / 2), nY);
                }

                nX += (m_AmmoColumns[3].Width + 10);

                // Caliber

                strText = String.Format("{0:G0}", Ammo.Caliber);

                TextSize = e.Graphics.MeasureString(strText, DataFont);

                e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX, nY);

                nX += (m_AmmoColumns[4].Width + 10);

                //----------------------------------------------------------------------------*
                // Min Stock Level
                //----------------------------------------------------------------------------*

                double dQuantity = Ammo.MinimumStockLevel;

                if (m_DataFiles.Preferences.TrackInventory)
                {
                    if (dQuantity != 0.0)
                    {
                        strText = String.Format("{0:G0}", dQuantity);
                    }
                    else
                    {
                        strText = "-";
                    }
                }
                else
                {
                    strText = "-";
                }

                TextSize = e.Graphics.MeasureString(strText, DataFont);

                e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + (m_AmmoColumns[5].Width / 2) - (TextSize.Width / 2), nY);

                nX += (m_AmmoColumns[5].Width + 20);

                //----------------------------------------------------------------------------*
                // Qty on Hand
                //----------------------------------------------------------------------------*

                nQtyX = nX - 10;

                dQuantity = m_DataFiles.SupplyQuantity(Ammo);

                if (dQuantity != 0.0)
                {
                    strText = String.Format("{0:N0}", dQuantity);
                }
                else
                {
                    strText = "-";
                }

                if (m_DataFiles.Preferences.TrackInventory)
                {
                    m_dTotalRounds += dQuantity;

                    m_dTotalCost += (dQuantity * m_DataFiles.SupplyCostEach(Ammo));
                }

                TextSize = e.Graphics.MeasureString(strText, DataFont);

                e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + (m_AmmoColumns[6].Width / 2) - (TextSize.Width / 2), nY);

                nX += (m_AmmoColumns[6].Width + 10);

                //----------------------------------------------------------------------------*
                // Estimated Cost
                //----------------------------------------------------------------------------*

                nCostX = nX - 10;

                double dBoxSize = 50;

                if (Ammo.FirearmType == cFirearm.eFireArmType.Rifle)
                {
                    dBoxSize = 20;
                }

                double dCostEach = m_DataFiles.SupplyCostEach(Ammo);

                if (dCostEach > 0.0)
                {
                    if (m_DataFiles.Preferences.TrackInventory && m_DataFiles.Preferences.AmmoShowCostPerBox)
                    {
                        strText = String.Format("{0:F2}/{1:F0}", m_DataFiles.SupplyCostEach(Ammo) * dBoxSize, dBoxSize);
                    }
                    else
                    {
                        strText = String.Format("{0:F2}", m_DataFiles.SupplyCostEach(Ammo) * dQuantity);
                    }
                }
                else
                {
                    strText = "-";
                }

                TextSize = e.Graphics.MeasureString(strText, DataFont);

                e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + m_AmmoColumns[7].Width - TextSize.Width - 10, nY);

                nX = nLeftMargin;

                nY += TextSize.Height;
            }

            e.HasMorePages = false;

            if (nQtyX > 0.0 && nCostX > 0.0)
            {
                PrintTotals(nY, e, DataFont, nQtyX, nCostX);
            }

            ResetPrintedFlag();
        }
Esempio n. 8
0
        //============================================================================*
        // OnPrintPage()
        //============================================================================*

        private void OnPrintPage(object sender, PrintPageEventArgs e)
        {
            //----------------------------------------------------------------------------*
            // Create the fonts
            //----------------------------------------------------------------------------*

//			Font TitleFont = new Font("Trebuchet MS", 16, FontStyle.Bold);
            Font SupplyTypeFont = new Font("Trebuchet MS", 14, FontStyle.Bold);
            Font HeaderFont     = new Font("Trebuchet MS", 10, FontStyle.Bold);
            Font DataFont       = new Font("Trebuchet MS", 8, FontStyle.Regular);

            //----------------------------------------------------------------------------*
            // Calculate Column Header Name Widths
            //----------------------------------------------------------------------------*

            string strText;
            SizeF  TextSize;

            foreach (cPrintColumn PrintColumn in m_BulletColumns)
            {
                TextSize = e.Graphics.MeasureString(PrintColumn.Name, HeaderFont);

                if (TextSize.Width > PrintColumn.Width)
                {
                    PrintColumn.Width = TextSize.Width;
                }
            }

            foreach (cPrintColumn PrintColumn in m_PowderColumns)
            {
                TextSize = e.Graphics.MeasureString(PrintColumn.Name, HeaderFont);

                if (TextSize.Width > PrintColumn.Width)
                {
                    PrintColumn.Width = TextSize.Width;
                }
            }

            foreach (cPrintColumn PrintColumn in m_CaseColumns)
            {
                TextSize = e.Graphics.MeasureString(PrintColumn.Name, HeaderFont);

                if (TextSize.Width > PrintColumn.Width)
                {
                    PrintColumn.Width = TextSize.Width;
                }
            }

            foreach (cPrintColumn PrintColumn in m_PrimerColumns)
            {
                TextSize = e.Graphics.MeasureString(PrintColumn.Name, HeaderFont);

                if (TextSize.Width > PrintColumn.Width)
                {
                    PrintColumn.Width = TextSize.Width;
                }
            }

            //----------------------------------------------------------------------------*
            // Calculate Header Widths for Supplies
            //----------------------------------------------------------------------------*

            foreach (cSupply Supply in m_SupplyList)
            {
                switch (Supply.SupplyType)
                {
                case cSupply.eSupplyTypes.Bullets:
                    TextSize = e.Graphics.MeasureString((Supply as cBullet).ToString(), DataFont);

                    if (TextSize.Width > m_BulletColumns[0].Width)
                    {
                        m_BulletColumns[0].Width = TextSize.Width;
                    }

                    break;

                case cSupply.eSupplyTypes.Powder:
                    TextSize = e.Graphics.MeasureString((Supply as cPowder).ToString(), DataFont);

                    if (TextSize.Width > m_PowderColumns[0].Width)
                    {
                        m_PowderColumns[0].Width = TextSize.Width;
                    }

                    break;

                case cSupply.eSupplyTypes.Primers:
                    TextSize = e.Graphics.MeasureString((Supply as cPrimer).ToShortString(), DataFont);

                    if (TextSize.Width > m_PrimerColumns[0].Width)
                    {
                        m_PrimerColumns[0].Width = TextSize.Width;
                    }

                    TextSize = e.Graphics.MeasureString((Supply as cPrimer).SizeString, DataFont);

                    if (TextSize.Width > m_PrimerColumns[1].Width)
                    {
                        m_PrimerColumns[1].Width = TextSize.Width;
                    }

                    TextSize = e.Graphics.MeasureString("0.00/1000", DataFont);

                    if (TextSize.Width > m_PrimerColumns[3].Width)
                    {
                        m_PrimerColumns[3].Width = TextSize.Width;
                    }
                    break;

                case cSupply.eSupplyTypes.Cases:
                    TextSize = e.Graphics.MeasureString((Supply as cCase).Manufacturer.Name, DataFont);

                    if (TextSize.Width > m_CaseColumns[0].Width)
                    {
                        m_CaseColumns[0].Width = TextSize.Width;
                    }

                    TextSize = e.Graphics.MeasureString((Supply as cCase).Caliber.ToString(), DataFont);

                    if (TextSize.Width > m_CaseColumns[2].Width)
                    {
                        m_CaseColumns[2].Width = TextSize.Width;
                    }

                    break;
                }
            }

            //----------------------------------------------------------------------------*
            // Loop through the supply types
            //----------------------------------------------------------------------------*

            Rectangle PageRect = e.PageBounds;

            int nXDPI = (int)((double)PageRect.Width / 8.5);
            int nYDPI = (int)((double)PageRect.Height / 11);

            PageRect.X     += (int)((double)nXDPI * 0.5);
            PageRect.Width -= ((int)((double)nXDPI * 0.5) * 2);

            PageRect.Y      += (int)((double)nYDPI * 0.5);
            PageRect.Height -= ((int)((double)nYDPI * 0.5) * 2);

            float nY = PageRect.Top;
            float nX = PageRect.Left;

            bool fPageHeader = false;

            for (int nSupplyType = 0; nSupplyType < (int)cSupply.eSupplyTypes.NumSupplyTypes; nSupplyType++)
            {
                cSupply.eSupplyTypes eSupplyType = (cSupply.eSupplyTypes)nSupplyType;

                //----------------------------------------------------------------------------*
                // Loop through the supplies in the list
                //----------------------------------------------------------------------------*

                bool fHeader = false;

                foreach (cSupply Supply in m_SupplyList)
                {
                    if (nY > PageRect.Bottom)
                    {
                        e.HasMorePages = true;

                        return;
                    }

                    //----------------------------------------------------------------------------*
                    // If this supply is not the right type, or has already been printed, skip
                    // to the next supply in the list
                    //----------------------------------------------------------------------------*

                    if (Supply.Printed || Supply.SupplyType != eSupplyType)
                    {
                        continue;
                    }

                    Supply.Printed = true;

                    //----------------------------------------------------------------------------*
                    // Draw the page header if needed
                    //----------------------------------------------------------------------------*

                    if (!fPageHeader)
                    {
                        //----------------------------------------------------------------------------*
                        // Draw the Title
                        //----------------------------------------------------------------------------*

                        nY = cPrintObject.PrintReportTitle("Load Shopping List", e, PageRect);

                        if (m_DataFiles.Preferences.TrackInventory)
                        {
                            strText = m_DataFiles.CostText;

                            TextSize = e.Graphics.MeasureString(strText, HeaderFont);

                            e.Graphics.DrawString(strText, HeaderFont, Brushes.Black, (PageRect.Width / 2) - (TextSize.Width / 2), nY);

                            nY += TextSize.Height;
                        }

                        nY += HeaderFont.Height;

                        fPageHeader = true;
                        fHeader     = false;
                    }

                    //----------------------------------------------------------------------------*
                    // Draw the supply type header if needed
                    //----------------------------------------------------------------------------*

                    if (!fHeader)
                    {
                        //----------------------------------------------------------------------------*
                        // Draw the supply type
                        //----------------------------------------------------------------------------*

                        switch (eSupplyType)
                        {
                        //----------------------------------------------------------------------------*
                        // Bullets
                        //----------------------------------------------------------------------------*

                        case cSupply.eSupplyTypes.Bullets:
                            strText = "Bullets";

                            TextSize = e.Graphics.MeasureString(strText, SupplyTypeFont);

                            nY += (TextSize.Height * (float)0.5);

                            e.Graphics.DrawString(strText, SupplyTypeFont, Brushes.Black, nX, nY);

                            nY += (TextSize.Height * (float)1.5);
                            nX  = PageRect.Left;

                            foreach (cPrintColumn PrintColumn in m_BulletColumns)
                            {
                                e.Graphics.DrawString(PrintColumn.Name, HeaderFont, Brushes.Black, nX, nY);

                                nX += (PrintColumn.Width + 20);
                            }

                            TextSize = e.Graphics.MeasureString(m_BulletColumns[0].Name, HeaderFont);

                            nY += TextSize.Height;

                            e.Graphics.DrawLine(Pens.Black, PageRect.Left, nY, nX, nY);

                            nX = PageRect.Left;

                            break;

                        //----------------------------------------------------------------------------*
                        // Powder
                        //----------------------------------------------------------------------------*

                        case cSupply.eSupplyTypes.Powder:
                            strText = "Powder";

                            TextSize = e.Graphics.MeasureString(strText, SupplyTypeFont);

                            nY += (TextSize.Height * (float)0.5);

                            e.Graphics.DrawString(strText, SupplyTypeFont, Brushes.Black, nX, nY);

                            nY += (TextSize.Height * (float)1.5);
                            nX  = PageRect.Left;

                            foreach (cPrintColumn PrintColumn in m_PowderColumns)
                            {
                                e.Graphics.DrawString(PrintColumn.Name, HeaderFont, Brushes.Black, nX, nY);

                                nX += (PrintColumn.Width + 20);
                            }

                            TextSize = e.Graphics.MeasureString(m_PowderColumns[0].Name, HeaderFont);

                            nY += TextSize.Height;

                            e.Graphics.DrawLine(Pens.Black, PageRect.Left, nY, nX, nY);

                            nX = PageRect.Left;

                            break;

                        //----------------------------------------------------------------------------*
                        // Primers
                        //----------------------------------------------------------------------------*

                        case cSupply.eSupplyTypes.Primers:
                            strText = "Primers";

                            TextSize = e.Graphics.MeasureString(strText, SupplyTypeFont);

                            nY += (TextSize.Height * (float)0.5);

                            e.Graphics.DrawString(strText, SupplyTypeFont, Brushes.Black, nX, nY);

                            nY += (TextSize.Height * (float)1.5);
                            nX  = PageRect.Left;

                            foreach (cPrintColumn PrintColumn in m_PrimerColumns)
                            {
                                e.Graphics.DrawString(PrintColumn.Name, HeaderFont, Brushes.Black, nX, nY);

                                nX += (PrintColumn.Width + 20);
                            }

                            TextSize = e.Graphics.MeasureString(m_PrimerColumns[0].Name, HeaderFont);

                            nY += TextSize.Height;

                            e.Graphics.DrawLine(Pens.Black, PageRect.Left, nY, nX, nY);

                            nX = PageRect.Left;


                            break;

                        //----------------------------------------------------------------------------*
                        // Cases
                        //----------------------------------------------------------------------------*

                        case cSupply.eSupplyTypes.Cases:
                            strText = "Cases";

                            TextSize = e.Graphics.MeasureString(strText, SupplyTypeFont);

                            nY += (TextSize.Height * (float)0.5);

                            e.Graphics.DrawString(strText, SupplyTypeFont, Brushes.Black, nX, nY);

                            nY += (TextSize.Height * (float)1.5);
                            nX  = PageRect.Left;

                            foreach (cPrintColumn PrintColumn in m_CaseColumns)
                            {
                                e.Graphics.DrawString(PrintColumn.Name, HeaderFont, Brushes.Black, nX, nY);

                                nX += (PrintColumn.Width + 20);
                            }

                            TextSize = e.Graphics.MeasureString(m_CaseColumns[0].Name, HeaderFont);

                            nY += TextSize.Height;

                            e.Graphics.DrawLine(Pens.Black, PageRect.Left, nY, nX, nY);

                            nX = PageRect.Left;

                            break;
                        }

                        fHeader = true;
                    }

                    //----------------------------------------------------------------------------*
                    // Draw the supply info
                    //----------------------------------------------------------------------------*

                    switch (eSupplyType)
                    {
                    //----------------------------------------------------------------------------*
                    // Bullets
                    //----------------------------------------------------------------------------*

                    case cSupply.eSupplyTypes.Bullets:
                        cBullet Bullet = (cBullet)Supply;

                        //----------------------------------------------------------------------------*
                        // Bullet Name
                        //----------------------------------------------------------------------------*

                        strText = Bullet.ToString();

                        nX = PageRect.Left;

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX, nY);

                        nX += (m_BulletColumns[0].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Bullet Diameter
                        //----------------------------------------------------------------------------*

                        strText = String.Format("{0:F3}", Bullet.Diameter);

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + (m_BulletColumns[1].Width / 2) - (TextSize.Width / 2), nY);

                        nX += (m_BulletColumns[1].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Bullet Weight
                        //----------------------------------------------------------------------------*

                        strText = String.Format("{0:G0}", Bullet.Weight);

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + (m_BulletColumns[2].Width / 2) - (TextSize.Width / 2), nY);

                        nX += (m_BulletColumns[2].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Qty on Hand
                        //----------------------------------------------------------------------------*

                        double dQuantity = m_DataFiles.SupplyQuantity(Supply);

                        if (m_DataFiles.Preferences.TrackInventory)
                        {
                            if (dQuantity != 0.0)
                            {
                                strText = String.Format("{0:G0}", dQuantity);
                            }
                            else
                            {
                                strText = "-";
                            }
                        }
                        else
                        {
                            strText = "-";
                        }

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + (m_BulletColumns[3].Width / 2) - (TextSize.Width / 2), nY);

                        nX += (m_BulletColumns[3].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Estimated Cost
                        //----------------------------------------------------------------------------*

                        if (dQuantity != 0.0)
                        {
                            strText = String.Format("{0}{1:F2}/100", m_DataFiles.Preferences.Currency, m_DataFiles.SupplyCostEach(Supply) * 100.0);
                        }
                        else
                        {
                            strText = "-";
                        }

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + m_BulletColumns[4].Width - TextSize.Width, nY);

                        nX = PageRect.Left;

                        nY += TextSize.Height;

                        break;

                    //----------------------------------------------------------------------------*
                    // Powder
                    //----------------------------------------------------------------------------*

                    case cSupply.eSupplyTypes.Powder:
                        cPowder Powder = (cPowder)Supply;

                        //----------------------------------------------------------------------------*
                        // Powder Name
                        //----------------------------------------------------------------------------*

                        strText = Powder.ToString();

                        nX = PageRect.Left;

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX, nY);

                        nX += (m_PowderColumns[0].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Powder Type
                        //----------------------------------------------------------------------------*

                        strText = Powder.FirearmType.ToString();

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX, nY);

                        nX += (m_PowderColumns[1].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Powder shape
                        //----------------------------------------------------------------------------*

                        strText = Powder.Shape.ToString();

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX, nY);

                        nX += (m_PowderColumns[2].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Qty on Hand
                        //----------------------------------------------------------------------------*

                        dQuantity = cDataFiles.StandardToMetric(m_DataFiles.SupplyQuantity(Powder) / 7000.0, cDataFiles.eDataType.CanWeight);

                        if (m_DataFiles.Preferences.TrackInventory)
                        {
                            if (dQuantity != 0.0)
                            {
                                strText = String.Format("{0:F3}", dQuantity);
                            }
                            else
                            {
                                strText = "-";
                            }
                        }
                        else
                        {
                            strText = "-";
                        }

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + (m_PowderColumns[3].Width / 2) - (TextSize.Width / 2), nY);

                        nX += (m_PowderColumns[3].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Estimated Cost
                        //----------------------------------------------------------------------------*

                        if (dQuantity != 0.0)
                        {
                            strText = String.Format("{0}{1:F2}/{2}", m_DataFiles.Preferences.Currency, cDataFiles.StandardToMetric(m_DataFiles.SupplyCostEach(Powder) * 7000.0, cDataFiles.eDataType.CanWeight), cDataFiles.MetricString(cDataFiles.eDataType.CanWeight));
                        }
                        else
                        {
                            strText = "-";
                        }

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + m_PowderColumns[4].Width - TextSize.Width, nY);

                        nX = PageRect.Left;

                        nY += TextSize.Height;

                        break;

                    //----------------------------------------------------------------------------*
                    // Primers
                    //----------------------------------------------------------------------------*

                    case cSupply.eSupplyTypes.Primers:
                        cPrimer Primer = (cPrimer)Supply;

                        //----------------------------------------------------------------------------*
                        // Primer
                        //----------------------------------------------------------------------------*

                        strText = Primer.ToShortString();

                        nX = PageRect.Left;

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX, nY);

                        nX += (m_PrimerColumns[0].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Size
                        //----------------------------------------------------------------------------*

                        strText = Primer.Size.ToString();

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX, nY);

                        nX += (m_PrimerColumns[1].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Magnum
                        //----------------------------------------------------------------------------*

                        strText = Primer.Magnum ? "Yes" : "No";

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + (m_PrimerColumns[2].Width / 2) - (TextSize.Width / 2), nY);

                        nX += (m_PrimerColumns[2].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Qty on Hand
                        //----------------------------------------------------------------------------*

                        dQuantity = m_DataFiles.SupplyQuantity(Supply);

                        if (m_DataFiles.Preferences.TrackInventory)
                        {
                            if (dQuantity != 0.0)
                            {
                                strText = String.Format("{0:G0}", dQuantity);
                            }
                            else
                            {
                                strText = "-";
                            }
                        }
                        else
                        {
                            strText = "-";
                        }

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + (m_PrimerColumns[3].Width / 2) - (TextSize.Width / 2), nY);

                        nX += (m_PrimerColumns[3].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Estimated Cost
                        //----------------------------------------------------------------------------*

                        if (dQuantity != 0.0)
                        {
                            strText = String.Format("{0}{1:F2}/1000", m_DataFiles.Preferences.Currency, m_DataFiles.SupplyCostEach(Supply) * 1000);
                        }
                        else
                        {
                            strText = "-";
                        }

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + m_PrimerColumns[4].Width - TextSize.Width, nY);

                        nX = PageRect.Left;

                        nY += TextSize.Height;

                        break;

                    //----------------------------------------------------------------------------*
                    // Cases
                    //----------------------------------------------------------------------------*

                    case cSupply.eSupplyTypes.Cases:
                        cCase Case = (cCase)Supply;

                        //----------------------------------------------------------------------------*
                        // Manufacturer
                        //----------------------------------------------------------------------------*

                        strText = Case.Manufacturer.ToString();

                        nX = PageRect.Left;

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX, nY);

                        nX += (m_CaseColumns[0].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Match
                        //----------------------------------------------------------------------------*

                        strText = "Y";

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        if (Case.Match)
                        {
                            e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + (m_CaseColumns[1].Width / 2) - (TextSize.Width / 2), nY);
                        }

                        nX += (m_CaseColumns[1].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Caliber
                        //----------------------------------------------------------------------------*

                        strText = Case.Caliber.ToString();

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX, nY);

                        nX += (m_CaseColumns[2].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Qty on Hand
                        //----------------------------------------------------------------------------*

                        dQuantity = m_DataFiles.SupplyQuantity(Supply);

                        if (m_DataFiles.Preferences.TrackInventory)
                        {
                            if (dQuantity != 0.0)
                            {
                                strText = String.Format("{0:G0}", dQuantity);
                            }
                            else
                            {
                                strText = "-";
                            }
                        }
                        else
                        {
                            strText = "-";
                        }

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + (m_CaseColumns[3].Width / 2) - (TextSize.Width / 2), nY);

                        nX += (m_CaseColumns[3].Width + 20);

                        //----------------------------------------------------------------------------*
                        // Estimated Cost
                        //----------------------------------------------------------------------------*

                        if (dQuantity != 0.0)
                        {
                            strText = String.Format("{0}{1:F2}/100", m_DataFiles.Preferences.Currency, m_DataFiles.SupplyCostEach(Supply) * 100);
                        }
                        else
                        {
                            strText = "-";
                        }

                        TextSize = e.Graphics.MeasureString(strText, DataFont);

                        e.Graphics.DrawString(strText, DataFont, Brushes.Black, nX + m_CaseColumns[4].Width - TextSize.Width, nY);

                        nX = PageRect.Left;

                        nY += TextSize.Height;

                        break;
                    }
                }
            }

            e.HasMorePages = false;

            ResetPrintedFlag();
        }