Esempio n. 1
0
        /// <summary> 从通达信文件中加载 行业、行业明细 板块数据
        /// </summary>
        private Dictionary <string, int> LoadHyHyDetBlockDataFile(List <StockBlockType> lstStockBlockType)
        {
            Dictionary <string, int> retDic    = new Dictionary <string, int>();
            const string             formatMod = "{0},{1},{2}";

            if (lstStockBlockType.Contains(StockBlockType.hy))
            {
                string[] fileNameSplit      = BLL.StockBlockFileName(StockBlockType.hy).Split(',');
                string   fileNamIncon       = (CommProp.TDXFolder + fileNameSplit[0]).Replace(@"\\", @"\");
                string   fileNameHy         = (CommProp.TDXFolder + fileNameSplit[1]).Replace(@"\\", @"\");
                string   blockTypeNameHy    = BLL.StockBlockTypeName(StockBlockType.hy),
                         blockTypeNameHyDet = BLL.StockBlockTypeName(StockBlockType.hyDet);

                // 获取 行业、行业明细 代码对应名称
                TupleValue <Dictionary <string, string>, Dictionary <string, string> > tupleDic = this.GetHyHydetDictionary(fileNamIncon);
                Dictionary <string, string> dicHy    = tupleDic.Value1;
                Dictionary <string, string> dicHyDet = tupleDic.Value2;

                // 股票代码与其 行业、行业明细 代码对应
                string[] lines = File.ReadAllLines(fileNameHy, Encoding.Default);
                foreach (string line in lines)
                {
                    string[] split = line.Split('|');
                    if (split.Length != 4)
                    {
                        break;
                    }

                    string stockCode = split[1];
                    string hyDetCode = split[2];
                    string hyCode    = split[3];

                    if (dicHy.ContainsKey(hyCode))
                    {
                        string key = string.Format(formatMod, stockCode, blockTypeNameHy, dicHy[hyCode]);
                        retDic.Add(key, 0);
                    }

                    if (dicHyDet.ContainsKey(hyDetCode))
                    {
                        string key = string.Format(formatMod, stockCode, blockTypeNameHyDet, dicHyDet[hyDetCode]);
                        retDic.Add(key, 0);
                    }
                }
            }

            return(retDic);
        }
Esempio n. 2
0
        /// <summary> 从通达信文件中加载 地区 板块数据
        /// </summary>
        private Dictionary <string, int> LoadDqBlockDataFile(StockBlockType blockType = StockBlockType.dq)
        {
            Dictionary <string, int> retDic = new Dictionary <string, int>();

            string[]     fileNameSplit = BLL.StockBlockFileName(StockBlockType.dq).Split(',');
            string       fileNameZs    = (CommProp.TDXFolder + fileNameSplit[0]).Replace(@"\\", @"\");
            string       fileNameDb    = (CommProp.TDXFolder + fileNameSplit[1]).Replace(@"\\", @"\");
            string       blockTypeName = BLL.StockBlockTypeName(blockType);
            const string formatMod     = "{0},{1},{2}";

            string[] lines = File.ReadAllLines(fileNameZs, Encoding.Default);
            Dictionary <string, string> dicDqName = new Dictionary <string, string>();

            foreach (string line in lines)
            {
                if (line.Length <= 0)
                {
                    break;
                }
                string[] split = line.Split('|');
                if (split.Length == 6 && split[2] == "3")
                {
                    dicDqName.Add(split[5], split[0]);
                }
            }

            DataTable baseDbf = BLL.LoadBaseDbf(fileNameDb);

            if (baseDbf != null && baseDbf.Rows.Count > 0)
            {
                foreach (DataRow dr in baseDbf.Rows)
                {
                    string dqCode = dr["DY"].ToString().Trim();
                    if (dicDqName.ContainsKey(dqCode))
                    {
                        string stockCode = dr["GPDM"].ToString().Trim();
                        string bkName    = dicDqName[dqCode];
                        string key       = string.Format(formatMod, stockCode, blockTypeName, bkName);
                        retDic.Add(key, 0);
                    }
                }
            }

            return(retDic);
        }
Esempio n. 3
0
        /// <summary> 从通达信文件中加载 概念、风格、指数 板块数据
        /// </summary>
        private Dictionary <string, int> LoadGnFgZsBlockDataFile(List <StockBlockType> lstStockBlockType)
        {
            /*
             * 通达信V6.1概念板块分类文件格式分析
             * http://blog.csdn.net/starsky2006/article/details/5863444
             */

            Dictionary <string, int> retDic    = new Dictionary <string, int>();
            const string             formatMod = "{0},{1},{2}";

            foreach (StockBlockType blockType in lstStockBlockType)
            {
                // 必须是 概念、风格、指数 之中的
                if (blockType != StockBlockType.gn && blockType != StockBlockType.fg && blockType != StockBlockType.zs)
                {
                    continue;
                }

                string blockTypeName = BLL.StockBlockTypeName(blockType); // 概念、风格、指数
                string fileName      = (CommProp.TDXFolder + BLL.StockBlockFileName(blockType)).Replace(@"\\", @"\");

                using (BinaryReader reader = new BinaryReader(File.OpenRead(fileName)))
                {
                    // 文件信息
                    string fileInfoStr = Encoding.Default.GetString(reader.ReadBytes(64)).TrimEnd('\0');

                    int indexStart  = reader.ReadInt32(); // 板块索引信息起始位置
                    int bkInfoStart = reader.ReadInt32(); // 板块记录信息起始位置

                    reader.BaseStream.Seek(indexStart, SeekOrigin.Begin);
                    // 索引名称
                    string indexName = Encoding.Default.GetString(reader.ReadBytes(64)).TrimEnd('\0');

                    reader.BaseStream.Seek(bkInfoStart, SeekOrigin.Begin);
                    // 板块数量
                    int bkCount = reader.ReadInt16();

                    // 第一个版块的起始位置为0x182h。
                    int offect = bkInfoStart + 2;
                    for (int i = 0; i < bkCount; i++)
                    {
                        reader.BaseStream.Seek(offect, SeekOrigin.Begin);
                        // 板块名称
                        string bkName = Encoding.Default.GetString(reader.ReadBytes(9)).TrimEnd('\0');
                        // 证券数量
                        int stockCount = reader.ReadInt16();
                        // 板块级别
                        int bkLevel = reader.ReadInt16();

                        // 每个板块最多包括400只股票。(2813 -9 - 2 - 2) / 7 =  400
                        for (int j = 0; j < 400; j++)
                        {
                            string stockCode = Encoding.Default.GetString(reader.ReadBytes(7)).TrimEnd('\0');
                            if (stockCode.Length == 0)
                            {
                                break;
                            }

                            string key = string.Format(formatMod, stockCode, blockTypeName, bkName);
                            retDic.Add(key, 0);
                        }

                        offect += 2813; // 每个板块占的长度为2813个字节。
                    }
                }
            }

            return(retDic);
        }