예제 #1
0
        private void btnCategorize_Click(object sender, EventArgs e)
        {
            try
            {
                if (lstPortfolio.Items.Count == 0)
                {
                    MessageBox.Show("Must be at least one trade.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtValueTrade.Focus();
                }
                else
                {
                    List <ITrade> trades = new List <ITrade>();
                    foreach (ListViewItem item in lstPortfolio.Items)
                    {
                        trades.Add((ITrade)item.Tag);
                    }

                    PortfolioCategorizer categorizer = new PortfolioCategorizer()
                    {
                        Categories = CategoryCollection.GetDefaultCategories()
                    };

                    List <string> categories = categorizer.Categorize(trades);

                    if (categories.Count != trades.Count)
                    {
                        MessageBox.Show("An unspected error ocourred on categorize.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    for (int i = 0; i < lstPortfolio.Items.Count; i++)
                    {
                        lstPortfolio.Items[i].SubItems[2].Text = categories[i];
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }