Example #1
0
        /// <summary>
        /// Creates and displays a table with a single Watchlist item on the page.
        /// </summary>
        /// <param name="item">WatchlistPlusQuote</param>
        /// <returns>Table</returns>
        private Table createWatchlistTable(WatchlistPlusQuote item)
        {
            Table    tbl       = new Table();
            TableRow row       = new TableRow();
            string   prefix    = string.Empty;
            string   classname = string.Empty;

            for (int i = 0; i < headers.Length; i++)
            {
                TableCell cell = new TableCell();
                row.Cells.Add(cell);
            }

            if (item.PriceChange > 0)
            {
                prefix    = "+";
                classname = "green";
            }
            if (item.PriceChange < 0)
            {
                classname = "red";
            }
            row.Cells[0].Text    = item.SymbolName + new HtmlString(String.Format(" <span class='subtext'>({0})</span>", item.LongName));
            row.Cells[1].Text    = String.Format("{0:C}", item.CurrentPrice);
            row.Cells[1].ToolTip = String.Format("as of {0}", item.Timestamp);
            row.Cells[2].Text    = new HtmlString(String.Format("<span class='{0}'>{1:C}</span>", classname, item.PriceChange)).ToString();
            row.Cells[3].Text    = new HtmlString(String.Format("<span class='{0}'>{1:P}</span>", classname, item.ChangePercent)).ToString();

            if (isPortfolio())             // create Remove button for each row or a lock for portfolio
            {
                Button btnLocked = new Button();
                btnLocked.CssClass = "symbol-button";
                btnLocked.Text     = HttpUtility.HtmlDecode("&#xe016;");
                btnLocked.ToolTip  = "This item is locked";
                btnLocked.Enabled  = false;
                row.Cells[headers.Length - 1].Controls.Add(btnLocked);
            }
            else             // otherwise create a remove button
            {
                Button btnRemove = new Button();
                btnRemove.CssClass = "delete symbol-button";
                btnRemove.Attributes.Add("Symbol", item.SymbolName);
                btnRemove.Attributes.Add("ListName", item.ListName);
                btnRemove.ID      = "btnRemove" + item.SymbolName;
                btnRemove.Text    = HttpUtility.HtmlDecode("&#xe007;");
                btnRemove.ToolTip = "Remove from list";
                btnRemove.Click  += btnRemove_Click;
                row.Cells[headers.Length - 1].Controls.Add(btnRemove);
            }
            // graph button
            Button btnGraph = new Button();

            btnGraph.CssClass = "symbol-button";
            btnGraph.Attributes.Add("Symbol", item.SymbolName);
            btnGraph.ID      = "btnGraph" + item.SymbolName;
            btnGraph.Text    = HttpUtility.HtmlDecode("&#xe019;");
            btnGraph.ToolTip = "View graph";
            btnGraph.Click  += new EventHandler(btnClick_generateChart);
            row.Cells[headers.Length - 1].Controls.Add(btnGraph);

            // buy/sell strategy signal button
            try
            {
                string summary = strategy.getSummary(item.SymbolName).CurrentSignal.ToString();
                if (summary.Equals("Buy") || summary.Equals("Sell"))
                {
                    Button btnSignal = new Button();
                    btnSignal.Attributes.Add("Symbol", item.SymbolName);
                    btnSignal.ID     = "btnSignal" + item.SymbolName;
                    btnSignal.Text   = summary;
                    btnSignal.Click += new EventHandler(btnClick_BuySell);
                    row.Cells[headers.Length - 1].Controls.Add(btnSignal);
                }
            }
            catch (Exception ex)
            {
                // meh
            }

            // Set widths
            for (int i = 0; i < widths.Length - 1; i++)
            {
                row.Cells[i].Width = new Unit(widths[i]);
            }
            // Set CSS classes
            tbl.CssClass = "main";
            row.CssClass = "main";
            tbl.Rows.Add(row);

            row.Cells[radioSortType.SelectedIndex / 2].CssClass = "bold";

            return(tbl);
        }
        /// <summary>
        /// Creates and displays a table with a single Watchlist item on the page.
        /// </summary>
        /// <param name="item">WatchlistPlusQuote</param>
        /// <returns>Table</returns>
        private Table createWatchlistTable(WatchlistPlusQuote item)
        {
            Table tbl = new Table();
            TableRow row = new TableRow();
            string prefix = string.Empty;
            string classname = string.Empty;

            for (int i = 0; i < headers.Length; i++)
            {
                TableCell cell = new TableCell();
                row.Cells.Add(cell);
            }

            if (item.PriceChange > 0)
            {
                prefix = "+";
                classname = "green";
            }
            if (item.PriceChange < 0)
            {
                classname = "red";
            }
            row.Cells[0].Text = item.SymbolName + new HtmlString(String.Format(" <span class='subtext'>({0})</span>", item.LongName));
            row.Cells[1].Text = String.Format("{0:C}", item.CurrentPrice);
            row.Cells[1].ToolTip = String.Format("as of {0}", item.Timestamp);
            row.Cells[2].Text = new HtmlString(String.Format("<span class='{0}'>{1:C}</span>", classname, item.PriceChange)).ToString();
            row.Cells[3].Text = new HtmlString(String.Format("<span class='{0}'>{1:P}</span>", classname, item.ChangePercent)).ToString();

            if (isPortfolio()) // create Remove button for each row or a lock for portfolio
            {
                Button btnLocked = new Button();
                btnLocked.CssClass = "symbol-button";
                btnLocked.Text = HttpUtility.HtmlDecode("&#xe016;");
                btnLocked.ToolTip = "This item is locked";
                btnLocked.Enabled = false;
                row.Cells[headers.Length - 1].Controls.Add(btnLocked);
            }
            else // otherwise create a remove button
            {
                Button btnRemove = new Button();
                btnRemove.CssClass = "delete symbol-button";
                btnRemove.Attributes.Add("Symbol", item.SymbolName);
                btnRemove.Attributes.Add("ListName", item.ListName);
                btnRemove.ID = "btnRemove" + item.SymbolName;
                btnRemove.Text = HttpUtility.HtmlDecode("&#xe007;");
                btnRemove.ToolTip = "Remove from list";
                btnRemove.Click += btnRemove_Click;
                row.Cells[headers.Length - 1].Controls.Add(btnRemove);
            }
            // graph button
            Button btnGraph = new Button();
            btnGraph.CssClass = "symbol-button";
            btnGraph.Attributes.Add("Symbol", item.SymbolName);
            btnGraph.ID = "btnGraph" + item.SymbolName;
            btnGraph.Text = HttpUtility.HtmlDecode("&#xe019;");
            btnGraph.ToolTip = "View graph";
            btnGraph.Click += new EventHandler(btnClick_generateChart);
            row.Cells[headers.Length - 1].Controls.Add(btnGraph);

            // buy/sell strategy signal button
            try
            {
                string summary = strategy.getSummary(item.SymbolName).CurrentSignal.ToString();
                if (summary.Equals("Buy") || summary.Equals("Sell"))
                {
                    Button btnSignal = new Button();
                    btnSignal.Attributes.Add("Symbol", item.SymbolName);
                    btnSignal.ID = "btnSignal" + item.SymbolName;
                    btnSignal.Text = summary;
                    btnSignal.Click += new EventHandler(btnClick_BuySell);
                    row.Cells[headers.Length - 1].Controls.Add(btnSignal);
                }
            }
            catch (Exception ex)
            {
                // meh
            }

            // Set widths
            for (int i = 0; i < widths.Length - 1; i++)
            {
                row.Cells[i].Width = new Unit(widths[i]);
            }
            // Set CSS classes
            tbl.CssClass = "main";
            row.CssClass = "main";
            tbl.Rows.Add(row);

            row.Cells[radioSortType.SelectedIndex / 2].CssClass = "bold";

            return tbl;
        }