예제 #1
0
        private void webClientPs3_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                string jsonInput = e.Result;
                saveOnFile(jsonInput, "ps3.json");
                var rootObject = JsonConvert.DeserializeObject <RootObject>(jsonInput);
                var stocks     = rootObject.Stocks;

                StockRepository.getInstance().setStocksPs3(stocks);

                ps3Stocks.ItemsSource = StockRepository.getInstance().StocksPs3;
            }
            catch (Exception ex)
            {
                if (!error)
                {
                    MessageBox.Show("No internet connection. Please verify your phone's connectivity and then hit the reload button.", "WASTED!", MessageBoxButton.OK);
                    error = true;

                    try
                    {
                        loadOfflineStocks();
                        MessageBox.Show("You are viewing the last loaded version of the stocks. Check your internet connection and then hit the reload button.");
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show("There's no cached information of the BAWSAQ stocks. Please, check your internet connection and then hit the reload button.", "BUSTED!", MessageBoxButton.OK);
                    }
                }
            }
        }
예제 #2
0
        public MainPage()
        {
            InitializeComponent();
            StockRepository.getInstance();

            loadStocks();

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
예제 #3
0
        public Page1()
        {
            InitializeComponent();
            StockHistory h = new StockHistory();

            h.Add(new StockHistoryInfo("seg", 100));
            h.Add(new StockHistoryInfo("ter", 50));

            ((LineSeries)myChart.Series[0]).ItemsSource = StockRepository.getInstance().getStockPs3(0).getHistory();
        }
예제 #4
0
        public void loadOfflineStocks()
        {
            var rootObject = JsonConvert.DeserializeObject <RootObject>(readFromFile("ps3.json"));
            var stocks     = rootObject.Stocks;

            StockRepository.getInstance().setStocksPs3(stocks);
            ps3Stocks.ItemsSource = StockRepository.getInstance().StocksPs3;

            rootObject = JsonConvert.DeserializeObject <RootObject>(readFromFile("xbox.json"));
            stocks     = rootObject.Stocks;
            StockRepository.getInstance().setStocksXbox(stocks);
            xboxStocks.ItemsSource = StockRepository.getInstance().StocksXbox;
        }
        // When page is navigated to set data context to selected item in list
        async protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string selectedIndex = "";
            string platform;

            NavigationContext.QueryString.TryGetValue("platform", out platform);
            if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
            {
                int   index = int.Parse(selectedIndex);
                Stock s     = null;
                if (platform.Equals("ps3"))
                {
                    s = StockRepository.getInstance().getStockPs3(index);
                }
                else
                {
                    s = StockRepository.getInstance().getStockXbox(index);
                }

                Uri         uri       = new Uri("/stockLogos/stock-" + s.CompanyCode + ".png", UriKind.Relative);
                ImageSource imgSource = new BitmapImage(uri);
                StockLogo.Source = imgSource;

                StockHistory h      = s.getHistory();
                AreaSeries   series = (AreaSeries)this.chart.Series[0];
                series.ItemsSource = h;

                if (s.PriceMovementDirection.Equals("down"))
                {
                    PriceMovementDirection.Foreground = new SolidColorBrush(Color.FromArgb(255, 204, 0, 0));
                    PriceMovement.Foreground          = new SolidColorBrush(Color.FromArgb(255, 204, 0, 0));
                    PriceMovementPercent.Foreground   = new SolidColorBrush(Color.FromArgb(255, 204, 0, 0));
                    s.PriceMovementDirection          = "6";
                }
                else
                {
                    PriceMovementDirection.Foreground = new SolidColorBrush(Color.FromArgb(255, 108, 148, 56));
                    PriceMovement.Foreground          = new SolidColorBrush(Color.FromArgb(255, 108, 148, 56));
                    PriceMovementPercent.Foreground   = new SolidColorBrush(Color.FromArgb(255, 108, 148, 56));
                    s.PriceMovementDirection          = "5";
                }
                DataContext = s;
                //NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
            }
        }