示例#1
0
        /// <summary>
        /// 创建用户状态服务
        /// </summary>
        public UserCookieService()
        {
            String dataDir = DataCenter.GetUserPath();

            if (!CFileA.IsDirectoryExist(dataDir))
            {
                CFileA.CreateDirectory(dataDir);
            }
            String dataBasePath = DataCenter.GetUserPath() + "\\usercookies.db";

            m_connectStr = "Data Source = " + dataBasePath;
            if (!CFileA.IsFileExist(dataBasePath))
            {
                CreateTable();
            }
        }
示例#2
0
        /// <summary>
        /// 下载所有的A股市场股票历史数据
        /// </summary>
        public static void DownAllStockHistory(int index)
        {
            List <KwItem> availableItems = new List <KwItem>();

            foreach (KwItem item in EMSecurityService.KwItems.Values)
            {
                availableItems.Add(item);
            }
            int    itemsSize         = availableItems.Count;
            int    complexRightIndex = 0;
            String saveFilePath      = "";

            for (int i = index * 50; i < itemsSize && i < (index + 1) * 50; i++)
            {
                KwItem item = availableItems[i];
                complexRightIndex = 0;
                for (; complexRightIndex < m_complexRightType.Count; complexRightIndex++)
                {
                    try
                    {
                        String cmd = String.Format(GetSearchCmd(m_complexRightType[complexRightIndex], m_lstAIndicators, item.Code), Environment.NewLine);
                        if (String.IsNullOrEmpty(cmd))
                        {
                            continue;
                        }
                        DataSet dsResult = DataCenter.DataQuery.QueryIndicate(cmd) as DataSet;
                        if (dsResult == null || dsResult.Tables.Count == 0)
                        {
                            continue;
                        }
                        IDictionary <String, String[]> dicResult = GetDictionaryFromDataSet(dsResult, m_lstAIndicators);
                        if (dicResult.Count > 0)
                        {
                            String code = item.Code;
                            if (code.IndexOf(".") != -1)
                            {
                                code = code.Substring(code.IndexOf(".") + 1) + code.Substring(0, code.IndexOf("."));
                            }
                            String dir = DataCenter.GetAppPath() + "\\day\\";
                            if (!CFileA.IsDirectoryExist(dir))
                            {
                                CFileA.CreateDirectory(dir);
                            }
                            saveFilePath = dir + code + ".txt";
                            StringBuilder sbResult = new StringBuilder();
                            sbResult.AppendLine(item.Code + " " + item.Name + " 日线 前复权");
                            sbResult.AppendLine("      日期	    开盘	    最高	    最低	    收盘	    成交量	    成交额");
                            foreach (KeyValuePair <String, String[]> pair in dicResult)
                            {
                                sbResult.AppendLine(FormatStockInfo(pair.Value, ","));
                            }
                            sbResult.AppendLine("OWCHART荣誉出品");
                            CFileA.Write(saveFilePath, sbResult.ToString());
                            sbResult = null;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
                    }
                }
            }
        }