Exemple #1
0
        private void btnRetrieveYCharts_Click(object sender, RoutedEventArgs e)
        {
            if (comboDataSource.SelectedIndex == 0)
            {
                labelProgrammiStaatus.Content = "Retrieving data from YCharts.com ...";
                btnCalculateForecast.IsEnabled = false;
                string symbol = txtBoxAndmeteAllikas.Text;
                if (string.IsNullOrEmpty(symbol) || symbol.Equals("input company ticker here") || symbol.Contains("."))
                {
                    MessageBox.Show("Illegal symbol or no symbol specified.");
                    return;
                }
                _inputVm.LaeAndmed(symbol);

                if (!PasswordSet)
                {
                    string[] promptValue = Prompt.ShowDialog("Enter YCharts.com Username");

                    string user = promptValue[0];
                    string psw = promptValue[1];
                    _user = user;
                    _password = psw;

                }
                if (!string.IsNullOrEmpty(_user) && !string.IsNullOrEmpty(_password))
                {
                    if (panelForecast.DataContext != null)
                    {
                        _dcfVM.ClearTable();
                    }
                    panelForecast.DataContext = null;
                    panelDcfOutput.DataContext = null;
                    FinAnalysisVM finAnalysisVm = new FinAnalysisVM(dataGrid);
                    _finDataAdapter = new FinDataAdapter(finAnalysisVm, symbol, FinDataAdapter.DataSource.XLS);
                    _finDataAdapter.AddDcfInput(_dci);
                    _finDataAdapter.PrepareDataXLS(_user, _password, this);
                    panelQuarterlyData.DataContext = finAnalysisVm;

                    // need peaks seatud saama alles siis, kui andmed saabuvad YCharts.com-st
                    //labelProgrammiStaatus.Content = "Data retrieved from YCharts.com.";
                    //btnCalculateForecast.IsEnabled = true;
                }
                else
                {
                    PasswordSet = false;
                    MessageBox.Show("Enter username and password, fields cannot be empty.");

                }
            }
            else if (comboDataSource.SelectedIndex == 2)
            {
                btnLaeAndmed.IsEnabled = false;
                string programStatus = labelProgrammiStaatus.Content.ToString();
                labelProgrammiStaatus.Content = "Loading data from Google Finance.";
                GoogleFinanceScraper gfs = new GoogleFinanceScraper();
                var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); //get UI thread context
                string txtBoxAndmeteAllikasText = txtBoxAndmeteAllikas.Text;
                var task1 = Task.Factory.StartNew(() => gfs.GetData(txtBoxAndmeteAllikasText));
                task1.ContinueWith(task => {
                    if (gfs.DownloadedData == null)
                    {
                        MessageBox.Show("Failed to download data for this ticker (" + txtBoxAndmeteAllikasText + ").");
                        labelProgrammiStaatus.Content = programStatus;
                    }
                    else
                    {
                        if (panelForecast.DataContext != null)
                        {
                            _dcfVM.ClearTable();
                        }
                        panelDcfOutput.DataContext = null;
                        labelProgrammiStaatus.Content = "Data loaded from Google Finance.";
                        FinAnalysisVM finAnalysisVm = new FinAnalysisVM(dataGrid);
                        _finDataAdapter = new FinDataAdapter(_inputVm, finAnalysisVm, "", FinDataAdapter.DataSource.XML, gfs.XmlPath);
                        // testimiseks:
                        _finDataAdapter.AddMainWindow(this);
                        _finDataAdapter.AddDcfInput(_dci);

                        _finDataAdapter.PrepareData();
                        panelQuarterlyData.DataContext = finAnalysisVm;
                    }
                    btnLaeAndmed.IsEnabled = true;
                }, uiScheduler);
            }
        }
Exemple #2
0
        private void btnAvaXMLFail_Click(object sender, RoutedEventArgs e)
        {
            //_inputVm.LaeAndmed("csco");
            labelProgrammiStaatus.Content = "Loading XML data ...";
            btnCalculateForecast.IsEnabled = false;
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

                if (panelForecast.DataContext != null)
                {
                    _dcfVM.ClearTable();
                }
                panelDcfOutput.DataContext = null;
                txtBoxAndmeteAllikas.IsEnabled = true;
                txtBoxAndmeteAllikas.Text = dialog.FileName;
                //txtBoxAndmeteAllikas.Foreground = Brushes.Black;
                //txtBoxAndmeteAllikas.CaretIndex = txtBoxAndmeteAllikas.Text.Length;
                //labelProgrammiStaatus.Content = "Data loaded from XML file (" + dialog.SafeFileName + ").";
                //var rect = txtBoxAndmeteAllikas.GetRectFromCharacterIndex(txtBoxAndmeteAllikas.CaretIndex);
                //txtBoxAndmeteAllikas.ScrollToHorizontalOffset(rect.Right);
                FinAnalysisVM finAnalysisVm = new FinAnalysisVM(dataGrid);
                _finDataAdapter = new FinDataAdapter(_inputVm, finAnalysisVm, "", FinDataAdapter.DataSource.XML, dialog.FileName);
                // testimiseks:
                _finDataAdapter.AddMainWindow(this);
                _finDataAdapter.AddDcfInput(_dci);

                _finDataAdapter.PrepareData();
                panelQuarterlyData.DataContext = finAnalysisVm;
                //btnCalculateForecast.IsEnabled = true;
            }
        }