/// <summary> /// 执行秒表方法 /// </summary> /// <param name="timerID">秒表ID</param> public void OnTimer(int timerID) { if (m_timerID == timerID) { int scrollY = m_gridSecurities.VScrollBar.Pos; POINT fPoint = new POINT(0, m_gridSecurities.HeaderHeight + 1 + scrollY); POINT ePoint = new POINT(0, m_gridSecurities.Height - 10 + scrollY); GridRow fRow = m_gridSecurities.GetRow(fPoint); GridRow eRow = m_gridSecurities.GetRow(ePoint); while (eRow == null && ePoint.y > 0) { ePoint.y -= 10; eRow = m_gridSecurities.GetRow(ePoint); } if (fRow != null && eRow != null) { List <String> requestCodes = new List <String>(); for (int i = fRow.Index; i <= eRow.Index; i++) { requestCodes.Add(m_gridSecurities.GetRow(i).GetCell(0).Text); } int requestCodesSize = requestCodes.Count; String strCodes = ""; for (int i = 0; i < requestCodesSize; i++) { strCodes += requestCodes[i]; if (i != requestCodesSize) { strCodes += ","; } } LatestDataInfo dataInfo = new LatestDataInfo(); dataInfo.m_codes = strCodes; dataInfo.m_formatType = 1; m_quoteService.GetLatestDatas(m_latestDataRequestID, dataInfo); requestCodes.Clear(); } } }
/// <summary> /// 请求获取最新的数据 /// </summary> /// <param name="requestID"></param> /// <param name="dataInfo"></param> /// <returns></returns> public int PushLatestDatas(int requestID, LatestDataInfo dataInfo) { return((this.Send(FUNCTIONID_QUOTE_PUSHLATESTDATA, requestID, this.m_socketID, dataInfo) > 0) ? 1 : 0); }
/// <summary> /// 执行秒表方法 /// </summary> /// <param name="timerID">秒表ID</param> public override void OnTimer(int timerID) { base.OnTimer(timerID); if (m_timerID == timerID) { //是否绘图 bool paint = false; if (m_cellState == 1) { if (m_selectedCell != null && !m_selectedCell.IsDragging) { m_tick2++; if (m_isEditing) { if (m_tick2 > 20) { m_isEditing = false; paint = true; m_cellState = 0; Update(); } } else { if (m_tick2 > 20) { m_isEditing = true; m_cellState = 0; paint = true; Update(); } } } } //查询最新数据 if (m_tick % 50 == 0) { List <UserSecurityCategory> categories = new List <UserSecurityCategory>(); m_userSecurityService.GetCategories(categories); int categoriesSize = categories.Count; if (categoriesSize > 0) { LatestDataInfo dataInfo = new LatestDataInfo(); dataInfo.m_codes = categories[0].m_codes; dataInfo.m_formatType = 1; m_quoteService.GetLatestDatas(m_latestDataRequestID, dataInfo); categories.Clear(); } } int width = Width - 15, height = Height; int cellsSize = m_cells.Count; for (int i = 0; i < cellsSize; i++) { UserSecurityCellT2 cell = m_cells[i]; if (!cell.IsDragging) { RECT bounds = cell.Bounds; RECT paintRect = cell.PaintRect; //当前区域 int left = bounds.left, top = bounds.top, right = bounds.right, bottom = bounds.bottom; //绘图区域 int pLeft = paintRect.left, pTop = paintRect.top, pRight = paintRect.right, pBottom = paintRect.bottom; int subLeft = Math.Abs(left - pLeft), subTop = Math.Abs(top - pTop), subRight = Math.Abs(right - pRight), subBottom = Math.Abs(bottom - pBottom); if (subTop > height || subBottom > height) { paint = true; cell.Bounds = paintRect; } else { ///左 if (subLeft > 0) { paint = true; left = GetAnimationPos(left, pLeft); } //上 if (subTop > 0) { paint = true; top = GetAnimationPos(top, pTop); } //右 if (subRight > 0) { paint = true; right = GetAnimationPos(right, pRight); } //下 if (subBottom > 0) { paint = true; bottom = GetAnimationPos(bottom, pBottom); } cell.Bounds = new RECT(left, top, right, bottom); } } } m_tick++; if (m_tick > 1000) { m_tick = 0; } //关闭抖动 if (m_useAnimation && m_isEditing) { if (m_tick % 2 == 0) { paint = true; } } //绘图 if (paint) { Invalidate(); } } }
/// <summary> /// 调用控件线程方法 /// </summary> /// <param name="args">参数</param> public void OnInvoke(object args) { CMessage message = (CMessage)args; if (message.m_serviceID == m_quoteService.ServiceID) { LatestDataInfo dataInfo = new LatestDataInfo(); List <SecurityLatestData> datas = new List <SecurityLatestData>(); QuoteService.GetLatestDatas(ref dataInfo, datas, message.m_body, message.m_bodyLength); int datasSize = datas.Count; for (int i = 0; i < datasSize; i++) { m_latestDatas[datas[i].m_securityCode] = datas[i]; } datas.Clear(); } else { List <UserSecurityCategory> categories = new List <UserSecurityCategory>(); UserSecurityService.GetCategories(categories, message.m_body, message.m_bodyLength); UserSecurityCategory category = categories[0]; switch (message.m_functionID) { case UserSecurityService.FUNCTIONID_USERSECURITY_ADDCATEGORIES: AddCategoriesToCategoryGrid(categories); break; case UserSecurityService.FUNCTIONID_USERSECURITY_DELETECATEGORIES: RemoveCategoriesFromCategoryGrid(categories); break; case UserSecurityService.FUNCTIONID_USERSECURITY_UPDATECATEGORIES: UpdateCategoriesToCategoryGrid(categories); break; case UserSecurityService.FUNCTIONID_USERSECURITY_ADDSECURITIES: case UserSecurityService.FUNCTIONID_USERSECURITY_DELETESECURITIES: { String categoryID = ""; List <GridRow> selectedRows = m_gridCategory.SelectedRows; int selectedRowsSize = selectedRows.Count; if (selectedRowsSize > 0) { categoryID = selectedRows[0].GetCell(0).Text; } if (categoryID != null && categoryID == category.m_categoryID) { List <Security> securities = new List <Security>(); m_securityService.GetSecuritiesByCodes(category.m_codes, securities); if (message.m_functionID == UserSecurityService.FUNCTIONID_USERSECURITY_ADDSECURITIES) { AddSecuritiesToSecuritiesGrid(securities); } else if (message.m_functionID == UserSecurityService.FUNCTIONID_USERSECURITY_DELETESECURITIES) { RemoveSecuritiesFromSecuritiesGrid(securities); } } break; } } } m_window.Invalidate(); }
/// <summary> /// 调用控件线程方法 /// </summary> /// <param name="args">参数</param> public override void OnInvoke(object args) { base.OnInvoke(args); if (args != null) { CMessage message = (CMessage)args; if (message.m_requestID == m_requestID) { //分时数据 if (message.m_functionID == QuoteService.FUNCTIONID_QUOTE_PUSHLATESTDATA) { LatestDataInfo dataInfo = new LatestDataInfo(); List <SecurityLatestData> datas = new List <SecurityLatestData>(); QuoteService.GetLatestDatas(ref dataInfo, datas, message.m_body, message.m_bodyLength); SecurityLatestData latestData = datas[0]; if (latestData != null && latestData.m_securityCode == m_securityCode && !latestData.Equal(m_latestData)) { m_latestData = latestData; //设置保留小数的位数 int digit = 2; if (m_latestData.m_securityCode.StartsWith("1") || m_latestData.m_securityCode.StartsWith("5")) { digit = 3; } m_chart.Digit = digit; m_chart.RefreshData(); } } //LV2分时数据 else if (message.m_functionID == QuoteService.FUNCTIONID_QUOTE_PUSHLATESTDATALV2) { LatestDataInfoLV2 dataInfo = new LatestDataInfoLV2(); List <SecurityLatestDataLV2> datas = new List <SecurityLatestDataLV2>(); QuoteService.GetLatestDatasLV2(ref dataInfo, datas, message.m_body, message.m_bodyLength); SecurityLatestDataLV2 latestDataLV2 = datas[0]; if (latestDataLV2 != null && latestDataLV2.m_securityCode == m_securityCode && !latestDataLV2.Equal(m_latestDataLV2)) { m_latestDataLV2 = latestDataLV2; } } //成交数据 else if (message.m_functionID == QuoteService.FUNCTIONID_QUOTE_PUSHTRANSACTIONDATA) { String securityCode = ""; List <TransactionData> transactionDatas = new List <TransactionData>(); QuoteService.GetTransactionDatas(ref securityCode, transactionDatas, message.m_body, message.m_bodyLength); int transactionDatasSize = transactionDatas.Count; for (int i = 0; i < transactionDatasSize; i++) { TransactionData transactionData = transactionDatas[i]; DateTime date = CStrA.ConvertNumToDate(transactionData.m_date); GridRow row = new GridRow(); m_gridTransaction.InsertRow(0, row); TransactionDateCell dateCell = new TransactionDateCell(); dateCell.Text = date.ToString("HH:mm:ss"); row.AddCell(0, dateCell); GridCellStyle dateCellStyle = new GridCellStyle(); dateCellStyle.BackColor = COLOR.EMPTY; dateCellStyle.Font = new FONT("SimSun", 14, true, false, false); dateCellStyle.ForeColor = CDraw.PCOLORS_FORECOLOR2; dateCell.Style = dateCellStyle; TransactionDataDoubleCell priceCell = new TransactionDataDoubleCell(); priceCell.Digit = 2; priceCell.SetDouble(transactionData.m_price); row.AddCell(1, priceCell); GridCellStyle priceCellStyle = new GridCellStyle(); priceCellStyle.BackColor = COLOR.EMPTY; priceCellStyle.Font = new FONT("SimSun", 14, true, false, false); priceCellStyle.ForeColor = CDraw.GetPriceColor(transactionData.m_price, m_latestData.m_lastClose); priceCell.Style = priceCellStyle; TransactionDataDoubleCell volumeCell = new TransactionDataDoubleCell(); volumeCell.SetDouble(transactionData.m_volume); row.AddCell(2, volumeCell); GridCellStyle volumeCellStyle = new GridCellStyle(); volumeCellStyle.BackColor = COLOR.EMPTY; volumeCellStyle.Font = new FONT("SimSun", 14, true, false, false); if (transactionData.m_type == 0) { volumeCellStyle.ForeColor = CDraw.PCOLORS_FORECOLOR; } else if (transactionData.m_type == 1) { volumeCellStyle.ForeColor = CDraw.PCOLORS_UPCOLOR; } else { volumeCellStyle.ForeColor = CDraw.PCOLORS_DOWNCOLOR; } volumeCell.Style = volumeCellStyle; } m_gridTransaction.Update(); } } Invalidate(); } }