Example #1
0
        private void buttonEdit_Click(object sender, EventArgs e)
        {
            string  symbol  = dataGridView.SelectedRows[0].Cells[(int)COL_INDEX.SYMBOL].Value.ToString();
            Holding holding = m_portfolio.GetHolding(symbol);

            if (holding == null)
            {
                throw new NullReferenceException("Null holding.");
            }

            int    rowIndex    = dataGridView.SelectedRows[0].Index;
            int    occurance   = OccuranceInDataGridView(symbol);
            double buyPrice    = Convert.ToDouble(dataGridView.SelectedRows[0].Cells[(int)COL_INDEX.BUY_PRICE].Value);
            double shares      = Convert.ToDouble(dataGridView.SelectedRows[0].Cells[(int)COL_INDEX.SHARES].Value);
            string buyDate     = dataGridView.SelectedRows[0].Cells[(int)COL_INDEX.DATE].Value.ToString();
            double newBuyPrice = 0;
            double newShares   = 0;
            string newBuyDate  = "";
            string title       = "";

            //edit holding w/ 1 pos.
            if (occurance == 1 && holding.PositionCount == 1)
            {
                title = "Edit Holding";
            }
            //edit holding w/ multiple pos.
            else if (occurance == 1 && holding.PositionCount > 1)
            {
                //this should never happen because edit button is disabled
                throw new InvalidOperationException();
            }
            //edit a sub-pos
            else
            {
                title = "Edit Position";
            }

            m_AddEditForm = new AddEditForm(title, holding.GetPosition(holding.Symbol, shares, buyPrice, buyDate), AddEditForm.WINDOW_TYPE.EDIT_WINDOW);

            if (m_AddEditForm.ShowDialog() == DialogResult.OK)
            {
                newBuyPrice = m_AddEditForm.Position.BuyPrice;
                newShares   = m_AddEditForm.Position.Shares;
                newBuyDate  = m_AddEditForm.Position.BuyDate;

                holding.GetPosition(holding.Symbol, shares, buyPrice, buyDate).BuyPrice      = newBuyPrice;
                holding.GetPosition(holding.Symbol, shares, newBuyPrice, buyDate).Shares     = newShares;
                holding.GetPosition(holding.Symbol, newShares, newBuyPrice, buyDate).BuyDate = newBuyDate;

                UpdateDataGridView();

                dataGridView.Rows[rowIndex].Cells[0].Selected = true;
                m_modified = true;
            }
        }
Example #2
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            m_AddEditForm = new AddEditForm("Add Holding", AddEditForm.WINDOW_TYPE.ADD_WINDOW); //todo: leak?

            if (m_AddEditForm.ShowDialog() == DialogResult.OK)
            {
                m_portfolio.AddHolding(m_AddEditForm.Holding);
                UpdateDataGridView();
                //go to the last holding. -2 because last empty row plus the total row...
                dataGridView.Rows[dataGridView.RowCount - 3].Cells[0].Selected = true;

                if (m_portfolio.HoldingCount > 0)
                {
                    buttonEdit.Enabled   = true;
                    buttonDelete.Enabled = true;
                }

                m_modified = true;
            }
        }