/// <summary>
        /// Sets the current time span based on the button that was clicked, then initializes the new chart.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chooseTimeSpan(object sender, EventArgs e)
        {
            MercuryButton mb = sender as MercuryButton;

            if (typeOfStock == "candlestick")
            {
                dayButton.Enabled = false;
            }
            resetTimeSpanButtons();
            timeSpan     = mb.buttonType;
            mb.BackColor = c.mercuryBlue;
            initilizeChart(typeOfChart, timeSpan);
        }
Exemple #2
0
        /// <summary>
        /// Reset button
        /// </summary>
        public void resetButton(object sender)
        {
            MercuryButton b = sender as MercuryButton;

            //Set clicked boolean to true
            b.clicked = false;
            //Change back color
            if (b.Enabled == false)
            {
                b.BackColor = Color.LightGray;
            }
            else
            {
                b.BackColor = System.Drawing.ColorTranslator.FromHtml("#374140");
            }
        }
        /// <summary>
        /// Sets the current chart type based on the button that was clicked, then initialize the new chart.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chooseChartType(object sender, EventArgs e)
        {
            MercuryButton mb = sender as MercuryButton;

            typeOfChart = mb.buttonType;
            if (typeOfChart == "candlestick")
            {
                dayButton.Enabled = false;
            }
            else
            {
                dayButton.Enabled = true;
            }
            //Reset time span
            timeSpan = "month";
            resetchartButtons();
            resetTimeSpanButtons();
            initilizeChart(typeOfChart, "month");
            monthButton.BackColor = c.mercuryBlue;
            mb.BackColor          = c.mercuryBlue;
        }
Exemple #4
0
        /// <summary>
        ///  Method tat initilizes the components
        /// </summary>
        private void inilizeComponents()
        {
            newsInfoPanel = new TableLayoutPanel();
            // create new mercuryButtons for the sorting the list of stocks
            MercuryButton NewsNameButton = new MercuryButton("Symbol", "");

            NewsNameButton.Height = 35;
            NewsNameButton.Click += (sender, e) => { newsInfoButton_clicked(sender, e, "symbol"); };
            MercuryButton NewsTitleButton = new MercuryButton("Title", "");

            NewsTitleButton.Height = 35;
            NewsTitleButton.Click += (sender, e) => { newsInfoButton_clicked(sender, e, "title"); };
            MercuryButton NewsUpdatedButton = new MercuryButton("Published", "");

            NewsUpdatedButton.Height = 35;
            NewsUpdatedButton.Click += (sender, e) => { newsInfoButton_clicked(sender, e, "pubDate"); };
            // add them to panel
            newsInfoPanel.Controls.Add(NewsNameButton, 1, 1);
            newsInfoPanel.Controls.Add(NewsTitleButton, 2, 1);
            newsInfoPanel.Controls.Add(NewsUpdatedButton, 3, 1);
            newsInfoButtons = new MercuryButton[3];
            // add the labels to the array
            newsInfoButtons[0] = NewsUpdatedButton;
            newsInfoButtons[1] = NewsTitleButton;
            newsInfoButtons[2] = NewsNameButton;
            // create the infoLabel for stocks list
            stockInfoPanel   = new TableLayoutPanel();
            stockInfoButtons = new MercuryButton[6];
            // create new mercuryButtons for the sorting the list of stocks
            MercuryButton SymbolButton = new MercuryButton("Symbol", "");

            SymbolButton.Height = 35;
            SymbolButton.Click += (sender, e) => { stockInfoButton_clicked(sender, e, "Symbol"); };
            MercuryButton NameButton = new MercuryButton("Company", "");

            NameButton.Height = 35;
            NameButton.Click += (sender, e) => { stockInfoButton_clicked(sender, e, "Name"); };
            MercuryButton LatestButton = new MercuryButton("Latest €", "");

            LatestButton.Height = 35;
            LatestButton.Click += (sender, e) => { stockInfoButton_clicked(sender, e, "Latest"); };
            MercuryButton ChangeButton = new MercuryButton("Change €", "");

            ChangeButton.Height = 35;
            ChangeButton.Click += (sender, e) => { stockInfoButton_clicked(sender, e, "Change"); };
            MercuryButton PercentButton = new MercuryButton("Percent", "");

            PercentButton.Height = 35;
            PercentButton.Click += (sender, e) => { stockInfoButton_clicked(sender, e, "Percent"); };
            MercuryButton OpenValueButton = new MercuryButton("Opening €", "");

            OpenValueButton.Height = 35;
            OpenValueButton.Click += (sender, e) => { stockInfoButton_clicked(sender, e, "OpenVal"); };
            // add the labels to the panel
            stockInfoPanel.Controls.Add(SymbolButton, 1, 1);
            stockInfoPanel.Controls.Add(NameButton, 3, 1);
            stockInfoPanel.Controls.Add(LatestButton, 5, 1);
            stockInfoPanel.Controls.Add(ChangeButton, 7, 1);
            stockInfoPanel.Controls.Add(PercentButton, 9, 1);
            stockInfoPanel.Controls.Add(OpenValueButton, 13, 1);
            // add the labels to the array
            stockInfoButtons[0] = SymbolButton;
            stockInfoButtons[1] = NameButton;
            stockInfoButtons[2] = LatestButton;
            stockInfoButtons[3] = ChangeButton;
            stockInfoButtons[4] = PercentButton;
            stockInfoButtons[5] = OpenValueButton;
            // filler, last, next previous and last labels for traversing the list
            filler                   = new Label();
            filler.Margin            = new Padding(0);
            filler.FlatStyle         = FlatStyle.Flat;
            last                     = createSideStepperButton(">>");
            last.Size                = new System.Drawing.Size(33, 20);
            last.Click              += (sender, e) => { last_clicked(sender, e); };
            first                    = createSideStepperButton("<<");
            first.Size               = new System.Drawing.Size(33, 20);
            first.Click             += (sender, e) => { first_clicked(sender, e); };
            next                     = createSideStepperButton(">");
            next.Click              += (sender, e) => { next_clicked(sender, e); };
            previous                 = createSideStepperButton("<");
            previous.Click          += (sender, e) => { previous_clicked(sender, e); };
            nextPreviousPanel        = new FlowLayoutPanel();
            nextPreviousPanel.Height = 25;
        }
        /// <summary>
        /// Adds current stock to portfolio.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addStockToPortfolio(object sender, EventArgs e)
        {
            MercuryButton button = sender as MercuryButton;

            c.addToPortfolio(button.buttonType);
        }
        JsonHandler js;                                //Json handler
        /// <summary>
        /// Displays information about a stock.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="s"></param>
        /// <param name="m"></param>
        public InfoDisplay(String type, String s, String m)
        {
            //Set generic width of mercury buttons
            buttonWidth  = 120;
            buttonHeight = 30;
            js           = new JsonHandler();
            chartPanel   = new Panel();
            //Initialize controller class
            c      = new Controller();
            symbol = s;
            market = m;
            //Check if type is a stock or market
            typeOfStock = type;
            if (typeOfStock == "stock")
            {
                stockList = js.getSingleStock(market, symbol, "month");
            }
            //Type is market, create dummy stocks from market values
            else if (typeOfStock == "market")
            {
                //Markets can't be added to portfolio
                portfolioCompatible = false;
                //Empty stock list
                stockList = new List <Stock>();
                List <Market> marketList = js.getSingleMarket(market, "month");
                foreach (Market temp in marketList)
                {
                    //Assign stock from current market value
                    Stock tempStock = new Stock();
                    tempStock.Symbol  = temp.MarketName;
                    tempStock.Latest  = temp.Latest;
                    tempStock.OpenVal = temp.OpenVal;
                    tempStock.Updated = temp.Updated;
                    tempStock.Volume  = "-";
                    stockList.Add(tempStock);
                }
            }
            stockList      = checkStock(stockList);
            stockList      = c.sortStockList(stockList, "Updated", false);
            Padding        = new Padding(5, 3, 5, 3);
            this.BackColor = c.highlightWhite;

            //Get latest stock info
            Stock info = stockList.ElementAt(stockList.Count - 1);

            //Initialize panels
            chartTypePanel  = new FlowLayoutPanel();
            timeSpanPanel   = new FlowLayoutPanel();
            centerChartType = new FlowLayoutPanel();
            centerTimeSpan  = new FlowLayoutPanel();
            timeSpanFiller  = new Panel();
            chartTypeFiller = new Panel();
            stockInfoPanel  = new FlowLayoutPanel();
            //Create and add chart type buttons and listeners for charts
            //Candlestick
            candlestickButton        = new MercuryButton("Candlestick", "candlestick");
            candlestickButton.Click += new EventHandler(chooseChartType);
            candlestickButton.Width  = buttonWidth;
            candlestickButton.Height = buttonHeight;
            //Line chart (Latest)
            lineChartButton        = new MercuryButton("Latest", "line");
            lineChartButton.Click += new EventHandler(chooseChartType);
            lineChartButton.Width  = buttonWidth;
            lineChartButton.Height = buttonHeight;
            //Bar chart (Change)
            barChartButton        = new MercuryButton("Change", "bar");
            barChartButton.Click += new EventHandler(chooseChartType);
            barChartButton.Width  = buttonWidth;
            barChartButton.Height = buttonHeight;
            //Add chart type buttons to panel
            chartTypePanel.Controls.Add(lineChartButton);
            chartTypePanel.Controls.Add(candlestickButton);
            chartTypePanel.Controls.Add(barChartButton);
            //Add button and event listener to control timespan value
            dayButton          = new MercuryButton("Day", "day");
            dayButton.Click   += new EventHandler(chooseTimeSpan);
            dayButton.Width    = buttonWidth;
            dayButton.Height   = buttonHeight;
            weekButton         = new MercuryButton("Week", "week");
            weekButton.Click  += new EventHandler(chooseTimeSpan);
            weekButton.Width   = buttonWidth;
            weekButton.Height  = buttonHeight;
            monthButton        = new MercuryButton("Month", "month");
            monthButton.Click += new EventHandler(chooseTimeSpan);
            monthButton.Width  = buttonWidth;
            monthButton.Height = buttonHeight;
            //Add timespan buttons to panel
            timeSpanPanel.Controls.Add(monthButton);
            timeSpanPanel.Controls.Add(weekButton);
            timeSpanPanel.Controls.Add(dayButton);
            //Add stock control panel to display
            this.Controls.Add(stockInfoPanel);
            //Initialize labels containing stock info
            stockInfoLabel         = new Label();
            stockNameLabel         = new Label();
            stockInfoLabel.Height  = 30;
            stockNameLabel.Height  = 30;
            stockInfoLabel.Margin  = new Padding(0, 1, 0, 1);
            stockNameLabel.Margin  = new Padding(0, 1, 0, 1);
            stockInfoPanel.Padding = new Padding(0, 1, 0, 1);
            //Initialize stock name
            String stockName = "";

            /*
             * If the info panel displays market info, set the name
             * of the market based on the symbol.
             */
            switch (info.Symbol)
            {
            case "LSE":
                stockName = "London Stock Exchange";
                break;

            case "OMX":
                stockName = "Stockholm Stock Exchange";
                break;

            case "NYSE":
                stockName = "New York Stock Exchange";
                break;

            default:
                stockName = info.Name;
                break;
            }
            //Initialize new tooltip
            ToolTip tt = new ToolTip();

            /*
             * Set text of first label.
             * - Latest
             * - Opening value
             * - Change (percent)
             * - Volume
             */
            stockInfoLabel.Text = "Latest: " + info.Latest
                                  + "  |  Opening: " + info.OpenVal
                                  + "  |  Change: " + info.Percent
                                  + "  |  Volume: " + info.Volume;
            //Add tooltip to stock info label
            tt.SetToolTip(stockInfoLabel, stockInfoLabel.Text);
            //Set label to name and symbol of stock
            stockNameLabel.Text = stockName + "  |  " + info.Symbol;
            //Set font of info labels
            stockInfoLabel.Font = c.mercuryFont;
            stockNameLabel.Font = new Font("Segoe UI", 12, FontStyle.Regular);
            //Add labels to panel
            stockInfoPanel.Controls.Add(stockNameLabel);
            stockInfoPanel.Controls.Add(stockInfoLabel);
            //Add button for adding stocks to portfolio
            MercuryButton portfolio = new MercuryButton("Add to portfolio", info.Symbol);

            portfolio.Width  = 170;
            portfolio.Height = 30;
            //Disable portfolio if current type is market
            if (!portfolioCompatible)
            {
                portfolio.Enabled   = false;
                portfolio.BackColor = Color.LightGray;
            }
            //Add listener to portfolio button
            portfolio.Click += new EventHandler(addStockToPortfolio);
            //Add portfolio button to panel
            stockInfoPanel.Controls.Add(portfolio);
            //Add panels to info display
            this.Controls.Add(chartPanel);
            this.Controls.Add(centerChartType);
            //Add chart type and filler
            centerChartType.Controls.Add(chartTypeFiller);
            centerChartType.Controls.Add(chartTypePanel);
            //Add panel that centers time span buttons
            this.Controls.Add(centerTimeSpan);
            //Add time span and filler panel
            centerTimeSpan.Controls.Add(timeSpanFiller);
            centerTimeSpan.Controls.Add(timeSpanPanel);
            //Set all chart buttons to unclicked
            resetchartButtons();
            //Set all time span buttons to unclicked
            resetTimeSpanButtons();
            //Initialize new chart
            initilizeChart(typeOfChart, timeSpan);
            //Set line chart button to clicked
            lineChartButton.BackColor = c.mercuryBlue;
            //Set month button to clicked
            monthButton.BackColor = c.mercuryBlue;
            //Initliaze new integrated news list
            news = new IntegratedNewsList(symbol, m);
            //Set background color of news list
            news.BackColor = c.highlightWhite;
            //Assign news panel to news list
            newsPanel = news;
            //Add news panel to info display
            this.Controls.Add(newsPanel);
        }