private void setupTournamentHands(TreeNode parentNode, PokerFormat format)
        {
            DatabaseHandler databaseHandler = DatabaseHandler.getInstance();
            IAggregateFluent <TournamentSummary> tournaments = databaseHandler.GetAllTournaments()
                                                               .Aggregate().Match(Builders <TournamentSummary> .Filter.Where(h => h.SitAndGo == (format == PokerFormat.SitAndGo)));
            IAggregateFluent <HandHistory> allHands = databaseHandler.GetAllHands().Aggregate()
                                                      .Match(Builders <HandHistory> .Filter.Where(h => h.GameDescription.PokerFormat == format));
            IEnumerable <AggregateResult <Buyin> > allBuyins =
                tournaments.Group(h => h.Buyin, h => new AggregateResult <Buyin> {
                result = h.Key
            })
                .Sort(Builders <AggregateResult <Buyin> > .Sort.Ascending(b => b.result))
                .ToEnumerable();

            decimal lastBuyin = -0.01m;

            foreach (dynamic buyinObj in allBuyins)
            {
                Buyin buyin = buyinObj.result;

                if (buyin.Total == lastBuyin)
                {
                    continue;
                }
                lastBuyin = buyin.Total;
                IAggregateFluent <HandHistory> hands =
                    allHands.Match(Builders <HandHistory> .Filter.Where(h => h.GameDescription.TournamentSummary.Buyin.Total == buyin.Total));
                GroupHandTreeNode buyinNode =
                    new GroupHandTreeNode(string.Format("{0}{1} {2}", buyin.GetCurrencySymbol(),
                                                        buyin.Total,
                                                        HandCount(hands)),
                                          hands);
                dynamic allIds = hands.Group(h => h.GameDescription.TournamentId, h => new { name = h.Key }).ToEnumerable();

                foreach (dynamic idObj in allIds)
                {
                    string id = idObj.name;

                    if (!string.IsNullOrWhiteSpace(id))
                    {
                        IEnumerable <TournamentSummary> summaries = tournaments.Match(t => t.Id == id).ToEnumerable();

                        if (summaries.Count() > 0)
                        {
                            TournamentSummary summary = summaries.First();

                            IAggregateFluent <HandHistory> tournyHands =
                                allHands.Match(Builders <HandHistory> .Filter.Where(h => h.GameDescription.TournamentId == summary.Id));
                            buyinNode.Nodes.Add(new HandsTreeNode(summary.ToString(), tournyHands));
                        }
                    }
                }

                if (buyinNode.Nodes.Count > 0)
                {
                    parentNode.Nodes.Add(buyinNode);
                }
            }
        }
        public void SetupHandTreeView()
        {
            DatabaseHandler databaseHandler          = DatabaseHandler.getInstance();
            IMongoCollection <HandHistory> allHands  = databaseHandler.GetAllHands();
            IAggregateFluent <HandHistory> cashHands =
                allHands.Aggregate().Match(Builders <HandHistory> .Filter.Where(h => h.GameDescription.PokerFormat == PokerFormat.CashGame));
            GroupHandTreeNode cashGamesNode =
                new GroupHandTreeNode("Cash Games", cashHands);
            IEnumerable <AggregateResult <Limit> > limits =
                cashHands.Group(h => h.GameDescription.Limit, h => new AggregateResult <Limit> {
                result = h.Key
            })
                .Sort(Builders <AggregateResult <Limit> > .Sort.Ascending(l => l.result.BigBlind).Ascending(l => l.result.SmallBlind))
                .ToEnumerable();

            foreach (AggregateResult <Limit> limit in limits)
            {
                IAggregateFluent <HandHistory> hands =
                    cashHands.Match(Builders <HandHistory> .Filter.Where(h2 => h2.GameDescription.Limit.Equals(limit.result)));
                cashGamesNode.Nodes.Add(
                    new HandsTreeNode(string.Format("{0} {1}", limit.result.ToString(), HandCount(hands)), hands));
            }

            HandView.Nodes.Add(cashGamesNode);


            TreeNode sitAndGoNode = new TreeNode("Sit and Go");

            setupTournamentHands(sitAndGoNode, PokerFormat.SitAndGo);
            HandView.Nodes.Add(sitAndGoNode);

            TreeNode tournamentNode = new TreeNode("Tournaments");

            setupTournamentHands(tournamentNode, PokerFormat.MultiTableTournament);
            HandView.Nodes.Add(tournamentNode);

            HandView.BeforeExpand    += BeforeExpand;
            HandView.AfterCollapse   += AfterCollapse;
            HandView.ContextMenuStrip = new ContextMenuStrip();
            HandView.ContextMenuStrip.Items.Add(new QuickViewMenuItem(this));
            HandView.ContextMenuStrip.Items.Add(new ToolStripMenuItem("&Setup custom view...", null, (s, e) => SetupCustomView()));
        }