Ejemplo n.º 1
0
        private void ShowTweets()
        {
            this.pictureBox1.Image = Core.GetTopicImage(2, About);

            List <DbTweet> TweetList = TweetSet.ToList();

            if (Selection != SelectionWordRelated) // No se muestran los tweets relacionados con una palabra, sino los que cumplen con cierta característica.
            {
                if (Selection == SelectionFav)
                {
                    TweetList = TweetList.Where(x => x.RT > 1).ToList();
                    TweetList.Sort((x, y) => { return(-x.RT.CompareTo(y.RT)); });
                    if (TweetList.Count > 5)
                    {
                        TweetList.RemoveRange(5, TweetList.Count - 5);
                    }
                }
                if (Selection == SelectionPos)
                {
                    TweetList = TweetList.Where(x => x.PosValue > 0).ToList();
                    TweetList.Sort((x, y) => { return(-x.PosValue.CompareTo(y.PosValue)); });
                    if (TweetList.Count > 5)
                    {
                        TweetList.RemoveRange(5, TweetList.Count - 5);
                    }
                }
                if (Selection == SelectionNeg)
                {
                    TweetList = TweetList.Where(x => x.NegValue > 0).ToList();
                    TweetList.Sort((x, y) => { return(-x.NegValue.CompareTo(y.NegValue)); });
                    if (TweetList.Count > 5)
                    {
                        TweetList.RemoveRange(5, TweetList.Count - 5);
                    }
                }
                if (Selection == SelectionAmb)
                {
                    TweetList = TweetList.Where(x => x.PosValue > 0 && x.NegValue > 0).ToList();
                    TweetList.Sort((x, y) => { return(-(x.PosValue + x.NegValue).CompareTo(y.PosValue + y.NegValue)); });
                    if (TweetList.Count > 5)
                    {
                        TweetList.RemoveRange(5, TweetList.Count - 5);
                    }
                }
            }

            //tableLayoutPanel.RowStyles[0].Height = 24;

            foreach (DbTweet tw in TweetList)
            {
                RichTextBox toAdd = new RichTextBox()
                {
                    Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular), Width = 400, Height = 80, Padding = new Padding(3)
                };

                toAdd.Enabled   = false;
                toAdd.ForeColor = Color.FromArgb(50, 50, 50);
                toAdd.Text      = tw.Text;
                foreach (String w in tw.Terms)
                {
                    Color c = Color.FromArgb(255, 0, 0, 128);
                    if (Core.GetDbTopicFromAlias(w) != null)
                    {
                        c = Color.FromArgb(255, 255, 0, 255);

                        toAdd.Find(w);
                        toAdd.SelectionColor = c;
                        toAdd.SelectionFont  = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
                    }
                    else if (Core.words.ContainsKey(w))
                    {
                        if (Core.words[w] == 1)
                        {
                            c = Color.FromArgb(255, 0, 128, 0);
                        }
                        else if (Core.words[w] == -1)
                        {
                            c = Color.FromArgb(255, 128, 0, 0);
                        }
                        else if (Core.words[w] == 2)
                        {
                            c = Color.FromArgb(255, 128, 128, 255);
                        }
                        else
                        {
                            c = Color.FromArgb(255, 0, 0, 128);
                        }

                        toAdd.Find(w, RichTextBoxFinds.WholeWord);
                        toAdd.SelectionColor = c;
                    }
                }

                tableLayoutPanel.RowCount++;
                tableLayoutPanel.Controls.Add(new Label()
                {
                    Text = tw.Author, Padding = new Padding(3)
                }, 0, tableLayoutPanel.RowCount - 1);
                tableLayoutPanel.Controls.Add(toAdd, 1, tableLayoutPanel.RowCount - 1);
                //tableLayoutPanel.Controls.Add(new Label() { Text = tw.RT + "", Padding = new Padding(3) }, 2, tableLayoutPanel.RowCount - 1);

                tableLayoutPanel.Height += toAdd.Height;
            }

            tableLayoutPanel.Update();
        }