Ejemplo n.º 1
0
        //============================================================================*
        // OnRemoveActivityClicked()
        //============================================================================*

        private void OnRemoveActivityClicked(object sender, EventArgs e)
        {
            cTransaction Transaction = m_TransactionListView.SelectedItems[0].Tag as cTransaction;

            DialogResult rc = MessageBox.Show("Are you sure you wish to remove this activity from the list?", "Data Deletion Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

            if (rc != DialogResult.Yes)
            {
                return;
            }

            m_fChanged = true;

            m_Supply.TransactionList.Remove(Transaction);

            m_Supply.TransactionList.Sort();

            m_DataFiles.Preferences.LastTransactionSelected = null;

            m_TransactionListView.Populate();

            m_Supply.RecalculateInventory(m_DataFiles);

            PopulateInventoryData();

            UpdateButtons();
        }
Ejemplo n.º 2
0
        //============================================================================*
        // UpdateButtons()
        //============================================================================*

        private void UpdateButtons()
        {
            if (m_fViewOnly)
            {
                return;
            }

            cTransaction Transaction = null;

            if (m_TransactionListView.SelectedItems.Count > 0)
            {
                Transaction = (cTransaction)m_TransactionListView.SelectedItems[0].Tag;
            }

            if (Transaction == null)
            {
                EditActivityButton.Enabled   = false;
                RemoveActivityButton.Enabled = false;
            }
            else
            {
                EditActivityButton.Enabled   = (m_TransactionListView.SelectedItems.Count > 0 && Transaction.BatchID == 0);
                RemoveActivityButton.Enabled = (m_TransactionListView.SelectedItems.Count > 0 && Transaction.BatchID == 0);
            }
        }
Ejemplo n.º 3
0
        //============================================================================*
        // CompareTo()
        //============================================================================*

        public int CompareTo(Object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            cTransaction Transaction = (cTransaction)obj;

            //----------------------------------------------------------------------------*
            // Details
            //----------------------------------------------------------------------------*

            int rc = CompareDetailsTo(Transaction);

            //----------------------------------------------------------------------------*
            // Quantity
            //----------------------------------------------------------------------------*

            if (rc == 0)
            {
                rc = m_dQuantity.CompareTo(Transaction.m_dQuantity);

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

                if (rc == 0)
                {
                    rc = m_dCost.CompareTo(Transaction.m_dCost);
                }
            }

            return(rc);
        }
Ejemplo n.º 4
0
        //============================================================================*
        // OnEditActivityClicked()
        //============================================================================*

        private void OnEditActivityClicked(object sender, EventArgs e)
        {
            cTransaction Transaction = m_TransactionListView.SelectedItems[0].Tag as cTransaction;

            cTransactionForm TransactionForm = new cTransactionForm(Transaction, m_DataFiles);

            DialogResult rc = TransactionForm.ShowDialog();

            if (rc != DialogResult.OK)
            {
                return;
            }

            m_fChanged = true;

            m_Supply.TransactionList.Remove(Transaction);

            m_Supply.TransactionList.Add(TransactionForm.Transaction);

            m_Supply.TransactionList.Sort();

            m_TransactionListView.Populate();

            m_Supply.RecalculateInventory(m_DataFiles);

            m_DataFiles.Preferences.LastTransaction         = TransactionForm.Transaction;
            m_DataFiles.Preferences.LastTransactionSelected = TransactionForm.Transaction;

            PopulateInventoryData();

            UpdateButtons();
        }
Ejemplo n.º 5
0
        //============================================================================*
        // Verify()
        //============================================================================*

        public bool Verify(cTransaction Transaction)
        {
            if (!m_DataFiles.Preferences.ShowBatchTransactions && Transaction.BatchID != 0)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
0
        //============================================================================*
        // Append()
        //============================================================================*

        public void Append(cTransaction Transaction)
        {
            m_strSource = String.IsNullOrEmpty(m_strSource) ? Transaction.m_strSource : m_strSource;

            m_Supply = m_Supply == null ? Transaction.m_Supply : m_Supply;

            m_dQuantity = m_dQuantity == 0.0 ? Transaction.m_dQuantity : m_dQuantity;
            m_dCost     = m_dCost == 0.0 ? Transaction.m_dCost : m_dCost;
            m_dTax      = m_dTax == 0.0 ? Transaction.m_dTax : m_dTax;
            m_dShipping = m_dShipping == 0.0 ? Transaction.m_dShipping : m_dShipping;
            m_fApplyTax = !m_fApplyTax ? Transaction.m_fApplyTax : false;

            m_fChecked = !m_fChecked ? Transaction.m_fChecked : false;
        }
Ejemplo n.º 7
0
        //============================================================================*
        // cTransactionForm() - Constructor - Supply
        //============================================================================*

        public cTransactionForm(cSupply Supply, cDataFiles DataFiles)
        {
            InitializeComponent();

            m_DataFiles = DataFiles;

            m_Transaction = new cTransaction();

            m_Transaction.Supply = Supply;

            m_Transaction.TransactionType = m_DataFiles.Preferences.LastActivity;

            if (Supply is cAmmo)
            {
                m_fReload = (Supply as cAmmo).BatchID != 0;
            }

            switch (m_Transaction.TransactionType)
            {
            case cTransaction.eTransactionType.SetStockLevel:
                m_Transaction.Source = "";
                break;

            case cTransaction.eTransactionType.Purchase:
                m_Transaction.Source = m_DataFiles.Preferences.LastPurchaseSource;
                break;

            case cTransaction.eTransactionType.AddStock:
                m_Transaction.Source = m_DataFiles.Preferences.LastAddStockReason;
                break;

            case cTransaction.eTransactionType.ReduceStock:
                m_Transaction.Source = m_DataFiles.Preferences.LastReduceStockReason;
                break;

            case cTransaction.eTransactionType.Fired:
                m_Transaction.Source = m_DataFiles.Preferences.LastFiredLocation;
                break;
            }

            Text = "Add Activity";

            m_fAdd = true;

            OKButton.ButtonType = CommonLib.Controls.cOKButton.eButtonTypes.Add;

            Initialize();
        }
Ejemplo n.º 8
0
        //============================================================================*
        // Copy()
        //============================================================================*

        public void Copy(cTransaction Transaction)
        {
            m_fAutoTrans = Transaction.m_fAutoTrans;

            m_Date             = Transaction.m_Date;
            m_eTransactionType = Transaction.m_eTransactionType;
            m_strSource        = Transaction.m_strSource;

            m_Supply = Transaction.m_Supply;

            m_nBatchID = Transaction.m_nBatchID;

            m_dQuantity = Transaction.m_dQuantity;
            m_dCost     = Transaction.m_dCost;
            m_dTax      = Transaction.m_dTax;
            m_dShipping = Transaction.m_dShipping;
            m_fApplyTax = Transaction.m_fApplyTax;

            m_fChecked = Transaction.m_fChecked;
        }
Ejemplo n.º 9
0
        //============================================================================*
        // UpdateTransaction()
        //============================================================================*

        public ListViewItem UpdateTransaction(cTransaction Transaction, bool fSelect = false)
        {
            //----------------------------------------------------------------------------*
            // Find the Item
            //----------------------------------------------------------------------------*

            ListViewItem Item = null;

            foreach (ListViewItem CheckItem in Items)
            {
                if ((CheckItem.Tag as cTransaction).CompareTo(Transaction) == 0)
                {
                    Item = CheckItem;

                    break;
                }
            }

            //----------------------------------------------------------------------------*
            // If the item was not found, add it
            //----------------------------------------------------------------------------*

            if (Item == null)
            {
                return(AddTransaction(Transaction, fSelect));
            }

            //----------------------------------------------------------------------------*
            // Otherwise, update the Item Data
            //----------------------------------------------------------------------------*

            SetTransactionData(Item, Transaction);

            Item.Selected = fSelect;

            Focus();

            return(Item);
        }
Ejemplo n.º 10
0
        //============================================================================*
        // cTransactionForm() - Constructor - Transaction
        //============================================================================*

        public cTransactionForm(cTransaction Transaction, cDataFiles DataFiles, bool fReload = false)
        {
            InitializeComponent();

            m_Transaction = new cTransaction(Transaction);
            m_DataFiles   = DataFiles;
            m_fReload     = fReload;

            Text = "Edit Activity";

            m_fAdd = false;

            if (m_Transaction.Supply.SupplyType == cSupply.eSupplyTypes.Powder)
            {
                m_Transaction.Quantity /= 7000.0;
            }

            m_dRefQuantity = m_Transaction.Quantity;

            OKButton.ButtonType = CommonLib.Controls.cOKButton.eButtonTypes.Update;

            Initialize();
        }
Ejemplo n.º 11
0
        //============================================================================*
        // Comparer()
        //============================================================================*

        public static int Comparer(cTransaction Transaction1, cTransaction Transaction2)
        {
            if (Transaction1 == null)
            {
                if (Transaction2 != null)
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                if (Transaction2 == null)
                {
                    return(1);
                }
            }

            return(Transaction1.CompareTo(Transaction2));
        }
Ejemplo n.º 12
0
        //============================================================================*
        // AddTransaction()
        //============================================================================*

        public ListViewItem AddTransaction(cTransaction Transaction, bool fSelect = false)
        {
            if (!Verify(Transaction))
            {
                return(null);
            }

            //----------------------------------------------------------------------------*
            // Create and Add the Item
            //----------------------------------------------------------------------------*

            ListViewItem Item = new ListViewItem();

            SetTransactionData(Item, Transaction);

            AddItem(Item, fSelect);

            if (Transaction.CompareTo(m_DataFiles.Preferences.LastTransactionSelected) == 0)
            {
                Item.Selected = true;
            }

            return(Item);
        }
Ejemplo n.º 13
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("-");
            }
        }
Ejemplo n.º 14
0
        //============================================================================*
        // CompareDetailsTo()
        //============================================================================*

        public int CompareDetailsTo(cTransaction Transaction)
        {
            if (Transaction == null)
            {
                return(1);
            }

            //----------------------------------------------------------------------------*
            // Date
            //----------------------------------------------------------------------------*

            int rc = m_Date.CompareTo(Transaction.m_Date);

            //----------------------------------------------------------------------------*
            // AutoTrans
            //----------------------------------------------------------------------------*

            if (rc == 0)
            {
                rc = m_fAutoTrans.CompareTo(Transaction.m_fAutoTrans);

                //----------------------------------------------------------------------------*
                // TransactionType
                //----------------------------------------------------------------------------*

                if (rc == 0)
                {
                    rc = m_eTransactionType.CompareTo(Transaction.m_eTransactionType);

                    //----------------------------------------------------------------------------*
                    // Source
                    //----------------------------------------------------------------------------*

                    if (rc == 0)
                    {
                        if (m_strSource != null)
                        {
                            rc = m_strSource.CompareTo(Transaction.m_strSource);
                        }

                        //----------------------------------------------------------------------------*
                        // BatchID
                        //----------------------------------------------------------------------------*

                        if (rc == 0)
                        {
                            rc = m_nBatchID.CompareTo(Transaction.m_nBatchID);

                            //----------------------------------------------------------------------------*
                            // Supply
                            //----------------------------------------------------------------------------*

                            if (rc == 0)
                            {
                                switch (m_Supply.SupplyType)
                                {
                                case cSupply.eSupplyTypes.Ammo:
                                    rc = (m_Supply as cAmmo).CompareTo(Transaction.m_Supply as cAmmo);
                                    break;

                                case cSupply.eSupplyTypes.Bullets:
                                    rc = (m_Supply as cBullet).CompareTo(Transaction.m_Supply as cBullet);
                                    break;

                                case cSupply.eSupplyTypes.Cases:
                                    rc = (m_Supply as cCase).CompareTo(Transaction.m_Supply as cCase);
                                    break;

                                case cSupply.eSupplyTypes.Powder:
                                    rc = (m_Supply as cPowder).CompareTo(Transaction.m_Supply as cPowder);
                                    break;

                                case cSupply.eSupplyTypes.Primers:
                                    rc = (m_Supply as cPrimer).CompareTo(Transaction.m_Supply as cPrimer);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(rc);
        }
Ejemplo n.º 15
0
        //============================================================================*
        // 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);
                }
            }

            cTransaction Transaction1 = (cTransaction)(Object1 as ListViewItem).Tag;
            cTransaction Transaction2 = (cTransaction)(Object2 as ListViewItem).Tag;

            if (Transaction1 == null)
            {
                if (Transaction2 == null)
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                if (Transaction2 == null)
                {
                    return(1);
                }
            }

            bool fSpecial = false;
            int  rc       = 0;

            switch (SortColumn)
            {
            //----------------------------------------------------------------------------*
            // Date
            //----------------------------------------------------------------------------*

            case 0:
                rc = Transaction1.Date.CompareTo(Transaction2.Date);

                if (rc == 0)
                {
                    if (Transaction1.BatchID != 0)
                    {
                        rc = Transaction1.BatchID.CompareTo(Transaction2.BatchID);
                    }
                    else
                    {
                        rc = Transaction1.Source.CompareTo(Transaction2.Source);
                    }
                }

                fSpecial = true;

                break;

            //----------------------------------------------------------------------------*
            // Location/Reason
            //----------------------------------------------------------------------------*

            case 2:
                if (Transaction1.BatchID != 0)
                {
                    rc = Transaction1.BatchID.CompareTo(Transaction2.BatchID);
                }
                else
                {
                    rc = Transaction1.Source.CompareTo(Transaction2.Source);
                }

                fSpecial = true;

                break;

            //----------------------------------------------------------------------------*
            // Quantity
            //----------------------------------------------------------------------------*

            case 3:
                rc = Transaction1.Quantity.CompareTo(Transaction2.Quantity);

                fSpecial = true;

                break;

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

            case 4:
                rc = Transaction1.Cost.CompareTo(Transaction2.Cost);

                fSpecial = true;

                break;

            //----------------------------------------------------------------------------*
            // Tax
            //----------------------------------------------------------------------------*

            case 5:
                rc = Transaction1.Tax.CompareTo(Transaction2.Tax);

                fSpecial = true;

                break;

            //----------------------------------------------------------------------------*
            // Shipping
            //----------------------------------------------------------------------------*

            case 6:
                rc = Transaction1.Shipping.CompareTo(Transaction2.Shipping);

                fSpecial = true;

                break;

            //----------------------------------------------------------------------------*
            // Total
            //----------------------------------------------------------------------------*

            case 7:
                double dTotal1 = Transaction1.Cost + Transaction1.Tax + Transaction1.Shipping;
                double dTotal2 = Transaction2.Cost + Transaction2.Tax + Transaction2.Shipping;

                rc = dTotal1.CompareTo(dTotal2);

                fSpecial = true;

                break;
            }

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

                return(rc);
            }

            return(base.Compare(Object1, Object2));
        }
Ejemplo n.º 16
0
        //============================================================================*
        // cTransaction() - Copy Constructor
        //============================================================================*

        public cTransaction(cTransaction Transaction)
        {
            Copy(Transaction);
        }
        //============================================================================*
        // IncludeTransaction()
        //============================================================================*

        private bool IncludeTransaction(cTransaction Transaction)
        {
            //----------------------------------------------------------------------------*
            // Check Date Filters
            //----------------------------------------------------------------------------*

            if (Transaction.Date < m_StartDate || Transaction.Date > m_EndDate)
            {
                return(false);
            }

            //----------------------------------------------------------------------------*
            // Check Manufacturer if one is set
            //----------------------------------------------------------------------------*

            if (m_Manufacturer != null)
            {
                if (Transaction.Supply.Manufacturer.CompareTo(m_Manufacturer) != 0)
                {
                    return(false);
                }
            }

            //----------------------------------------------------------------------------*
            // Check Transaction Types
            //----------------------------------------------------------------------------*

            switch (Transaction.TransactionType)
            {
            //----------------------------------------------------------------------------*
            // Set Stock Level
            //----------------------------------------------------------------------------*

            case cTransaction.eTransactionType.SetStockLevel:
                if (!m_fInitialStock)
                {
                    return(false);
                }

                break;

            //----------------------------------------------------------------------------*
            // Check Purchase
            //----------------------------------------------------------------------------*

            case cTransaction.eTransactionType.Purchase:
                if (!m_fPurchases)
                {
                    return(false);
                }

                //----------------------------------------------------------------------------*
                // Check Purchase Location
                //----------------------------------------------------------------------------*

                if (!String.IsNullOrEmpty(m_strLocation))
                {
                    if (m_strLocation.ToUpper() != Transaction.Source.ToUpper())
                    {
                        return(false);
                    }
                }

                break;

            //----------------------------------------------------------------------------*
            // Check Adjustments
            //----------------------------------------------------------------------------*

            case cTransaction.eTransactionType.AddStock:
            case cTransaction.eTransactionType.ReduceStock:
                if (!m_fAdjustments)
                {
                    return(false);
                }

                break;

            //----------------------------------------------------------------------------*
            // Check Fired
            //----------------------------------------------------------------------------*

            case cTransaction.eTransactionType.Fired:
                if (!m_fFired)
                {
                    return(false);
                }

                break;

            //----------------------------------------------------------------------------*
            // Unknown Transaction Type, return false
            //----------------------------------------------------------------------------*

            default:
                return(false);
            }

            //----------------------------------------------------------------------------*
            // If we get to here, it must be ok
            //----------------------------------------------------------------------------*

            return(true);
        }