/// <summary> /// 过滤查找 /// </summary> public void FilterSearch() { String sText = m_searchTextBox.Text.ToUpper(); m_grid.BeginUpdate(); m_grid.ClearRows(); int row = 0; CList <GSecurity> securities = SecurityService.FilterCode(sText); if (securities != null) { int rowCount = securities.size(); for (int i = 0; i < rowCount; i++) { GSecurity security = securities.get(i); GridRow gridRow = new GridRow(); m_grid.AddRow(gridRow); gridRow.AddCell(0, new GridStringCell(security.m_code)); gridRow.AddCell(1, new GridStringCell(security.m_name)); row++; } } securities.Dispose(); m_grid.EndUpdate(); }
/// <summary> /// 选中行方法 /// </summary> private void OnSelectRow() { List <GridRow> rows = m_grid.SelectedRows; if (rows != null && rows.Count > 0) { GridRow selectedRow = rows[0]; GSecurity security = new GSecurity(); SecurityService.GetSecurityByCode(selectedRow.GetCell(0).Text, ref security); m_mainFrame.FindControl("txtCode").Text = security.m_code; Visible = false; Invalidate(); } }
/// <summary> /// 通过代码返回合约信息 /// </summary> /// <param name="code">合约代码</param> /// <param name="sd">out 股票基本信息</param> public static int GetSecurityByCode(String code, ref GSecurity security) { int ret = 0; foreach (String key in m_codedMap.Keys) { if (key == code) { security = m_codedMap[key]; ret = 1; break; } } return(ret); }
/// <summary> /// 单元格双击事件 /// </summary> /// <param name="sender">调用者</param> /// <param name="cell">单元格</param> /// <param name="mp">坐标</param> /// <param name="button">按钮</param> /// <param name="clicks">点击次数</param> /// <param name="delta">滚轮值</param> private void GridCellClick(object sender, GridCell cell, POINT mp, MouseButtonsA button, int clicks, int delta) { if (cell.Grid == m_tvIndicatorBrowser) { TreeNodeA tn = cell as TreeNodeA; if (tn.m_nodes.Count == 0) { NodeData nodeData = tn.Tag as NodeData; if (nodeData.IsCatalog) { IndicatorLeafDataPacket leafPacket = new IndicatorLeafDataPacket(nodeData.Id); ConnectManager.CreateInstance().Request(leafPacket); int tick = 0; while (leafPacket.ReserveFlag == 0 && tick < 50) { Thread.Sleep(100); tick++; } if (leafPacket.LeafNodeList.Count > 0) { List <NodeData> nodes = leafPacket.LeafNodeList; Dictionary <String, TreeNodeA> nodesMap = new Dictionary <String, TreeNodeA>(); int nodesSzie = nodes.Count; for (int i = 0; i < nodesSzie; i++) { NodeData node = nodes[i]; TreeNodeA subTn = new TreeNodeA(); subTn.Text = node.Name; subTn.Style = new GridCellStyle(); subTn.Style.ForeColor = COLOR.ARGB(255, 255, 80); subTn.Style.Font = new FONT("微软雅黑", 14, true, false, false); subTn.Name = node.Id; subTn.Tag = node; if (nodesMap.ContainsKey(node.ParentId)) { nodesMap[node.ParentId].AppendNode(subTn); nodesMap[node.Id] = subTn; } else { tn.AppendNode(subTn); nodesMap[node.Id] = subTn; } IndicatorEntityDataPacket entity = new IndicatorEntityDataPacket(node.Id); ConnectManager.CreateInstance().Request(entity); } tn.ExpendAll(); m_tvIndicatorBrowser.Update(); m_tvIndicatorBrowser.Invalidate(); } } else { StringBuilder sb = new StringBuilder(); CList <GSecurity> securities = SecurityService.FilterCode(m_txtIndicatorCode.Text); int codesSize = securities.size(); for (int i = 0; i < codesSize; i++) { sb.Append(securities.get(i).m_code); if (i != codesSize - 1) { sb.Append(","); } } m_gridIndicatorBrowser.ClearRows(); IndicatorRootData data = GetIndicatorData(nodeData.Id, "Stock", sb.ToString()); m_gridIndicatorBrowser.GetColumn("colN3").Text = data.categoryName; foreach (IndicatorItemData indicatorItem in data.items) { GridRow row = new GridRow(); m_gridIndicatorBrowser.AddRow(row); GridStringCell codeCell = new GridStringCell(indicatorItem.code); row.AddCell("colN1", codeCell); GSecurity security = new GSecurity(); SecurityService.GetSecurityByCode(indicatorItem.code, ref security); row.AddCell("colN2", new GridStringCell(security.m_name)); if (indicatorItem.type == 0) { GridStringCell valueCell = new GridStringCell(indicatorItem.text); row.AddCell("colN3", valueCell); } else if (indicatorItem.type == 1) { GridDoubleCell valueCell = new GridDoubleCell(indicatorItem.num); row.AddCell("colN3", valueCell); } row.GetCell("colN1").Style = new GridCellStyle(); row.GetCell("colN1").Style.ForeColor = COLOR.ARGB(255, 255, 80); row.GetCell("colN1").Style.Font = new FONT("微软雅黑", 14, true, false, false); row.GetCell("colN1").Style.Font = new FONT("微软雅黑", 14, true, false, false); row.GetCell("colN2").Style = new GridCellStyle(); row.GetCell("colN2").Style.ForeColor = COLOR.ARGB(255, 80, 80); row.GetCell("colN2").Style.Font = new FONT("微软雅黑", 14, true, false, false); row.GetCell("colN3").Style = new GridCellStyle(); row.GetCell("colN3").Style.ForeColor = COLOR.ARGB(80, 255, 255); row.GetCell("colN3").Style.Font = new FONT("微软雅黑", 14, true, false, false); } m_gridIndicatorBrowser.Update(); m_gridIndicatorBrowser.Invalidate(); } } } else if (cell.Grid == m_gridIndicatorBrowser) { if (clicks == 2) { m_mainFrame.SearchSecurity(cell.Row.GetCell("colN1").GetString()); } } }
/// <summary> /// 开始工作 /// </summary> private static void StartWork() { //加载代码表//step 1 String codes = ""; if (m_codedMap.Count == 0) { Dictionary <String, KwItem> items = EMSecurityService.KwItems; foreach (KwItem item in items.Values) { GSecurity security = new GSecurity(); security.m_code = item.Code; security.m_name = item.Name; security.m_pingyin = item.Pingyin; security.m_type = item.Type; if (!security.m_code.StartsWith("A")) { m_codedMap[security.m_code] = security; codes += security.m_code; codes += ","; } } } while (true) { 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 = StockService.GetSinaLatestDatasStrByCodes(latestCodes); if (latestDatasResult != null && latestDatasResult.Length > 0) { List <SecurityLatestData> latestDatas = new List <SecurityLatestData>(); StockService.GetLatestDatasBySinaStr(latestDatasResult, 0, latestDatas); String[] subStrs = latestDatasResult.Split(new String[] { ";\n" }, StringSplitOptions.RemoveEmptyEntries); 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_latestDatasStr[latestData.m_code] = subStrs[j]; //bool append = true; //if (m_latestDatas.ContainsKey(latestData.m_code)) //{ // if (!m_latestDatas[CStrA.ConvertFileCodeToMemoryCode(latestData.m_code)].Equals(latestData)) // { // append = false; // } //} //if(append) //{ // long today = (long)DateTime.Now.Subtract(DateTime.Parse("1970-1-1")).TotalMilliseconds / 86400000; // if (m_today < today) // { // m_today = today; // String nPath = DataCenter.GetAppPath() + "\\tick\\" + DateTime.Now.ToString("yyyy-MM-dd"); // if (!Directory.Exists(nPath)) // { // Directory.CreateDirectory(nPath); // } // m_newFileDir = nPath + "\\"; // } // String line = String.Format("{0},{1},{2},{3}\r\n", latestData.m_date,// // latestData.m_close, latestData.m_volume, latestData.m_amount); // CFileA.Append(m_newFileDir + latestData.m_code + ".txt", line); //} if (!m_latestDatas.ContainsKey(latestData.m_code)) { m_latestDatas[latestData.m_code] = latestData; } else { m_latestDatas[latestData.m_code].Copy(latestData); } if (latestData.m_code == "000001.SH") { m_shTradeTime = latestData.m_date; } } } latestDatas.Clear(); } latestCodes = ""; } else { latestCodes += ","; } } } Thread.Sleep(1); } }