/// <summary> /// 加载 /// </summary> /// <param name="loadAll">是否全部加载标记</param> public static bool Load() { String sPath = Application.StartupPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt"; if (!File.Exists(sPath)) { List <KwItem> items = DataCenter.EMSecurityService.GetKwItems(); Dictionary <String, KwItem> availableItems = EMSecurityService.GetAvailableItems(items); StringBuilder sb = new StringBuilder(); foreach (String key in availableItems.Keys) { kwItems2[availableItems[key].Innercode] = availableItems[key]; sb.Append(key + "," + availableItems[key].Name + "," + availableItems[key].Pingyin + "," + availableItems[key].Marketcode + "," + availableItems[key].Type.ToString() + "," + availableItems[key].State.ToString() + "\r\n"); } CFileA.Write(Application.StartupPath + "\\codes.txt", sb.ToString()); EMSecurityService.KwItems = availableItems; CFileA.Write(sPath, JsonConvert.SerializeObject(EMSecurityService.KwItems)); SecurityService.ImportSecurities(EMSecurityService.KwItems); return(false); } else { EMSecurityService.KwItems = JsonConvert.DeserializeObject <Dictionary <String, KwItem> >(File.ReadAllText(sPath, Encoding.Default)); foreach (String key in KwItems.Keys) { kwItems2[KwItems[key].Innercode] = KwItems[key]; } SecurityService.ImportSecurities(EMSecurityService.KwItems); return(true); } }
/// <summary> /// 查询按钮、重置按钮点击事件 /// </summary> /// <param name="sender">发送者</param> /// <param name="mp">坐标</param> /// <param name="button">按钮</param> /// <param name="clicks">点击事件</param> /// <param name="delta">滚轮滚动值</param> private void ClickButton(object sender, POINT mp, MouseButtonsA button, int clicks, int delta) { if (button == MouseButtonsA.Left && clicks == 1) { ControlA control = sender as ControlA; String name = control.Name; if (name == "btnSelectCodeDir") { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (DialogResult.OK == fbd.ShowDialog()) { GetTextBox("txtCodeDir").Text = fbd.SelectedPath; String codeDirCacheDir = DataCenter.GetAppPath() + "\\CODEDIR.txt"; CFileA.Write(codeDirCacheDir, fbd.SelectedPath); Native.Invalidate(); } fbd.Dispose(); } else if (name == "btnSelectDataDir") { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (DialogResult.OK == fbd.ShowDialog()) { GetTextBox("txtDataDir").Text = fbd.SelectedPath; String dataDirCacheDir = DataCenter.GetAppPath() + "\\DATADIR.txt"; CFileA.Write(dataDirCacheDir, fbd.SelectedPath); Native.Invalidate(); } fbd.Dispose(); } else if (name == "btnGenerate") { //GAIA_FUTURE_CPP_S1:PengChen,100%; String codeDir = GetTextBox("txtCodeDir").Text; String dataDir = GetTextBox("txtDataDir").Text; ProjectJidian pJidian = new ProjectJidian(); DataCenter.JidianService.Dir = codeDir; DataCenter.JidianService.GetJidian(ref pJidian); if (pJidian.Lines > 0) { CFileA.Write(dataDir + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".jidian", pJidian.ToString()); GetTextBox("txtResults").Text = pJidian.ToString(); Native.Invalidate(); } } } }
/// <summary> /// 保存组信息 /// </summary> /// <param name="groups">组列表</param> public static void SaveGroups(List <ChatGroup> groups) { String file = DataCenter.GetAppPath() + "\\groups.txt"; CFileA.Write(file, JsonConvert.SerializeObject(groups)); }
/// <summary> /// 数据落地线程工作 /// </summary> public static void StartWork3() { //复制数据 LoadHistoryDatas(); GetMinuteDatas(); //新旧数据合并 foreach (String oCode in m_historyDatas.Keys) { if (!m_latestDatas.ContainsKey(oCode) || !m_historyDatas.ContainsKey(oCode)) { continue; } SecurityLatestData securityLatestData = m_latestDatas[oCode]; List <SecurityData> oldSecurityDatas = m_historyDatas[oCode]; SecurityData oldSecurityData = oldSecurityDatas[oldSecurityDatas.Count - 1]; int myear = 0, mmonth = 0, mday = 0, mhour = 0, mmin = 0, msec = 0, mmsec = 0; CStrA.M130(oldSecurityData.m_date, ref myear, ref mmonth, ref mday, ref mhour, ref mmin, ref msec, ref mmsec); int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, msec2 = 0; CStrA.M130(securityLatestData.m_date, ref year, ref month, ref day, ref hour, ref min, ref sec, ref msec2); if (year >= myear && month >= mmonth && day >= mday) { SecurityData nSecurityData = new SecurityData(); nSecurityData.m_amount = securityLatestData.m_amount; nSecurityData.m_close = securityLatestData.m_close; nSecurityData.m_date = securityLatestData.m_date; nSecurityData.m_high = securityLatestData.m_high; nSecurityData.m_low = securityLatestData.m_low; nSecurityData.m_open = securityLatestData.m_open; nSecurityData.m_volume = securityLatestData.m_volume; if (day == mday) { m_historyDatas[oCode].RemoveAt(m_historyDatas[oCode].Count - 1); } m_historyDatas[oCode].Add(nSecurityData); } } String outputFileTemplate = DataCenter.GetAppPath() + "\\day\\{0}.txt"; String fileInfo = "{0} {1} 日线 前复权\r\n"; String title = " 日期 开盘 最高 最低 收盘 成交量 成交额\r\n"; String lineTemp = "{0},{1},{2},{3},{4},{5},{6}\r\n"; String timeFormatStr = "yyyy-MM-dd"; //写入文件 foreach (String code in m_historyDatas.Keys) { List <SecurityData> temp3 = m_historyDatas[code]; StringBuilder strbuff = new StringBuilder(); strbuff.Append(String.Format(fileInfo, m_codedMap[code].m_code, m_codedMap[code].m_name)); strbuff.Append(title); foreach (SecurityData sdt in temp3) { strbuff.Append(String.Format(lineTemp, // CStr.ConvertNumToDate(sdt.m_date).ToString(timeFormatStr), // sdt.m_open, // sdt.m_high, // sdt.m_low, // sdt.m_close, // sdt.m_volume, // sdt.m_amount)); } strbuff.Append("数据来源:通达信\r\n"); CFileA.Write(String.Format(outputFileTemplate, code), strbuff.ToString()); } }
/// <summary> /// 开始工作 /// </summary> private static void StartWork() { Dictionary <String, String> m_codesMap = new Dictionary <String, String>(); String codes = ""; while (true) { if (m_securities.Count == 0) { String codesStr = ""; CFileA.Read(DataCenter.GetAppPath() + "\\codes.txt", ref codesStr); String[] strs = codesStr.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); StringBuilder sb = new StringBuilder(); for (int i = 0; i < strs.Length; i++) { String[] subStrs = strs[i].Split(','); Security security = new Security(); security.m_code = subStrs[0]; security.m_name = subStrs[1]; lock (m_securities) { m_securities.Add(security); } m_codesMap[security.m_code] = security.m_name; codes += security.m_code; codes += ","; if (!security.m_code.StartsWith("A")) { sb.Append(security.m_code + "," + security.m_name + "\r\n"); } } CFileA.Write(DataCenter.GetAppPath() + "\\codes.txt", sb.ToString()); } if (codes != null && codes.Length > 0) { if (codes.EndsWith(",")) { codes.Remove(codes.Length - 1); } String[] strCodes = codes.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); int codesSize = strCodes.Length; String latestCodes = ""; for (int i = 0; i < codesSize; i++) { latestCodes += strCodes[i]; if (i == codesSize - 1 || (i > 0 && i % 50 == 0)) { String latestDatasResult = GetSinaLatestDatasStrByCodes(latestCodes); if (latestDatasResult != null && latestDatasResult.Length > 0) { List <SecurityLatestData> latestDatas = new List <SecurityLatestData>(); GetLatestDatasBySinaStr(latestDatasResult, 0, latestDatas); int latestDatasSize = latestDatas.Count; for (int j = 0; j < latestDatasSize; j++) { SecurityLatestData latestData = latestDatas[j]; if (latestData.m_close == 0) { latestData.m_close = latestData.m_buyPrice1; } if (latestData.m_close == 0) { latestData.m_close = latestData.m_sellPrice1; } lock (m_latestDatas) { m_latestDatas[latestData.m_securityCode] = latestData; } } latestDatas.Clear(); } latestCodes = ""; } else { latestCodes += ","; } } } Thread.Sleep(1); } }
/// <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); } } } }
/// <summary> /// 触发秒表事件 /// </summary> /// <param name="sender">调用者</param> /// <param name="timerID">秒表ID</param> private void CallTimerEvent(object sender, int timerID) { if (m_isOver) { return; } if (m_sky != null) { if (m_currentQuestion != null && m_mode >= 5 && m_currentQuestion.m_type != "极限") { TimeSpan ts = DateTime.Now - m_bulletTime; int bollSeconds = 30, totalSeconds = (int)ts.TotalSeconds; m_sky.Text = ""; if (totalSeconds >= bollSeconds) { Sound.Play("sound\\attbomb.wav"); m_sky.CreateBullets(6); m_bulletTime = DateTime.Now; } else if (totalSeconds == bollSeconds - 1) { Sound.Play("sound\\1.wav"); m_sky.Text = "1"; } else if (totalSeconds == bollSeconds - 2) { Sound.Play("sound\\2.wav"); m_sky.Text = "2"; } else if (totalSeconds == bollSeconds - 3) { Sound.Play("sound\\3.wav"); m_sky.Text = "3"; } else if (totalSeconds == bollSeconds - 4) { Sound.Play("sound\\bomb.wav"); m_sky.Text = "准备炸弹"; } TimeSpan ts2 = DateTime.Now - m_shadowTime; int shadownTime = 1, totalSeconds2 = (int)ts2.TotalSeconds; if (totalSeconds2 >= shadownTime) { m_shadowTime = DateTime.Now; } m_sky.OnTimer(timerID); } if (m_currentQuestion != null && (m_currentQuestion.m_type == "记忆" || m_currentQuestion.m_type == "算数")) { if (m_currentQuestion.m_answer == m_txtAnswer.Text) { for (int i = 0; i < 5; i++) { AddBarrage("回答正确", 0, 4 + i); } ChangeQuestion(); } } } double m_oldCurrentTick = m_currentTick; if (m_currentTick > 0) { TimeSpan ts = DateTime.Now - m_lastTime; bool bulletIsClick = true; foreach (Bullet bullet in m_sky.m_bullets) { if (!bullet.IsClick) { bulletIsClick = false; } } if (bulletIsClick) { m_currentTick -= (double)ts.Milliseconds / 1000; } if (m_currentTick <= 0) { if (m_questions != null) { m_answers[m_currentQuestion.m_title] = m_txtAnswer.Text; } if (m_currentQuestion != null && m_currentQuestion.m_type == "极限") { Native.ExportToImage(DataCenter.GetAppPath() + "\\成绩截图.jpg"); } m_lblTime.Text = "时间到了"; m_txtAnswer.Text = m_currentQuestion.m_type; m_currentTick = 0; ChangeQuestion(); } else { if (m_currentQuestion.m_type == "记忆") { if (m_totalTick - m_currentTick > m_totalTick / 2) { m_txtQuestion.Text = "不可见"; m_txtAnswer.ReadOnly = false; if (m_txtAnswer.Text == "请迅速记忆上面这串数字,在此文字消失时打出刚才那串数字") { m_txtAnswer.Text = ""; } } if (m_currentTick <= 2) { m_txtQuestion.Text = m_currentQuestion.m_answer; } } double finishTime = (double)((TimeSpan)(DateTime.Now - m_firstTime)).TotalMilliseconds / 1000; m_lblTime.Text = "还剩" + m_currentTick.ToString("0.00") + "秒 已用时" + finishTime.ToString("0.00") + "秒"; if (finishTime > 60 * m_examMinute) { m_answers[m_currentQuestion.m_title] = m_txtAnswer.Text; String file = DataCenter.GetAppPath() + "\\Result.txt"; StringBuilder sb = new StringBuilder(); int index = 1; foreach (String question in m_answers.Keys) { sb.AppendLine(index.ToString() + "." + question); sb.AppendLine(m_answers[question]); index++; } CFileA.Write(file, sb.ToString()); String examName = ""; CFileA.Read(DataCenter.GetAppPath() + "\\WriteYourName.txt", ref examName); String url = "http://" + m_ip + ":10009/sendresult?name=" + examName; HttpPostService postService = new HttpPostService(); postService.Post(url, sb.ToString()); m_txtAnswer.Text = "考试时间到,请等待考试结果!"; Native.Invalidate(); m_isOver = true; } } } if (m_mode == 5) { if (m_currentQuestion.m_type == "打字" || m_currentQuestion.m_type == "极限") { if (m_tick % 5 == 0) { AddBarrage(m_rd.Next(0, 2) == 0 ? "111" : "222", 2, m_rd.Next(3, 20)); } } } m_lastTime = DateTime.Now; m_tick++; if (m_tick > 10000) { m_tick = 0; } Native.Invalidate(); }