Exemplo n.º 1
0
        private void lbSourceList_DoubleClick(object sender, EventArgs e)
        {
            if (lbSourceList.SelectedItem == null)
            {
                return;
            }
            string selectedSource = lbSourceList.SelectedItem.ToString();

            if (tcCharts.TabPages.ContainsKey(selectedSource))
            {
                tcCharts.SelectTab(selectedSource);
            }
            else
            {
                var newTabPage = new ChartTabPage(selectedSource)
                {
                    Name = selectedSource
                };

                tcCharts.TabPages.Add(newTabPage);
                tcCharts.SelectTab(newTabPage);
                var selectTime = new SelectData();

                if (selectTime.ShowDialog() == DialogResult.OK)
                {
                    var chart = tcCharts.SelectedTab as ChartTabPage;
                    if (chart == null)
                    {
                        return;
                    }
                    KeyValuePair <DateTime, double>[] data;
                    if (!(Path.GetExtension(selectedSource) == ".mst"))
                    {
                        data = PrnFinancialParser.ParseFile(folderBrowserDialog.SelectedPath + "\\" +
                                                            selectedSource);
                    }
                    else
                    {
                        data = MstFinancialParser.ParseFile(folderBrowserDialog.SelectedPath + "\\" +
                                                            selectedSource);
                    }

                    if ((data == null) || (data.Count() == 0))
                    {
                        return;
                    }

                    var selectedData = new Stack <KeyValuePair <DateTime, double> >();

                    foreach (var d in data.Where(d => (d.Key >= selectTime.DateFrom) && (d.Key <= selectTime.DateTo)))
                    {
                        selectedData.Push(d);
                    }

                    if (!selectedData.Any())
                    {
                        MessageBox.Show("Brak danych w podanym zakresie.");
                        return;
                    }

                    chart.FixedValues = selectedData.ToArray();
                    chart.UpdateFixedSeries(selectedSource);
                    valueCount.Text = "Value count: " + chart.FixedValues.Length;
                }
            }
        }