Пример #1
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (repository == null)
            {
                repository = new IndicatorRepository(textBox2.Text);
                repository.Initilization();
            }

            if (radioButton5.Checked)//飞狐交易师CSV格式
            {
                DirectoryInfo dInfo  = new DirectoryInfo(textBox3.Text);
                FileInfo[]    fInfos = dInfo.GetFiles("*.csv");
                int           num    = 0;
                for (int i = 0; i < fInfos.Length; i++)
                {
                    FileInfo x     = fInfos[i];
                    KLine    kline = new KLine(x.Name.Substring(2, 6), Utility.Collections.Time.TimeUnit.day);
                    kline.Load(x.FullName, false, ",", new String[] { "时间", "开盘", "最高", "最低", "收盘", "成交量", "成交额" });

                    toolStripStatusLabel1.Text = "导入" + kline.Code + "...";
                    Application.DoEvents();
                    TimeSerialsDataSet ds = repository[kline.Code];
                    if (ds == null)
                    {
                        continue;
                    }

                    ds.DayKLine = kline;
                    num        += 1;
                }
                MessageBox.Show("导入完成,共有" + num + "个日线完成导入");
            }
            else if (radioButton6.Checked)//通达信金融终端TXT格式
            {
                String[]      columns = { "时间", "开盘", "最高", "最低", "收盘", "成交量", "成交额" };
                DirectoryInfo dInfo   = new DirectoryInfo(textBox3.Text);
                FileInfo[]    fInfos  = dInfo.GetFiles("*.txt");
                int           num     = 0;
                for (int i = 0; i < fInfos.Length; i++)
                {
                    FileInfo x     = fInfos[i];
                    String   code  = x.Name.Substring(3, 6);
                    KLine    kline = new KLine(code, Utility.Collections.Time.TimeUnit.day);
                    String[] lines = File.ReadAllLines(x.FullName);
                    if (lines == null || lines.Length <= 0)
                    {
                        continue;
                    }
                    List <String> strs = lines.ToList();
                    strs.RemoveAt(0);
                    strs.RemoveAt(0);
                    strs.RemoveAt(strs.Count - 1);
                    kline.Load(strs.ToArray(), columns);
                    kline.ForEach(y => y["code"] = code);

                    toolStripStatusLabel1.Text = "导入" + kline.Code + "...";
                    Application.DoEvents();
                    TimeSerialsDataSet ds = repository[kline.Code];
                    if (ds == null)
                    {
                        continue;
                    }

                    ds.DayKLine = kline;
                    num        += 1;
                }
                MessageBox.Show("导入完成,共有" + num + "个日线完成导入");
            }
        }