/// <summary> /// 定时检查 /// </summary> public void Check() { m_planService.OnTimer(); Dictionary <int, GridColumn> columnsIndex = new Dictionary <int, GridColumn>(); List <GridColumn> columns = m_gridPlan.GetColumns(); int columnsSize = columns.Count; for (int i = 0; i < columnsSize; i++) { GridColumn column = columns[i]; columnsIndex[CStr.ConvertStrToInt(column.Name.Substring(4))] = column; } Dictionary <String, String> pids = new Dictionary <String, String>(); List <CPlan> plans = new List <CPlan>(); DataCenter.PlanService.GetPlans(plans); int plansSize = plans.Count; for (int i = 0; i < plansSize; i++) { pids[plans[i].m_id] = ""; } GridRow selectedRow = null; Dictionary <String, GridRow> rowsMap = new Dictionary <String, GridRow>(); List <GridRow> rows = m_gridPlan.GetRows(); int rowsSize = rows.Count; for (int i = 0; i < rowsSize; i++) { GridRow row = rows[i]; String id = ""; if (row.GetCell("colP1") != null) { id = row.GetCell("colP1").GetString(); } if (pids.ContainsKey(id)) { rowsMap[id] = row; } else { m_gridPlan.RemoveRow(row); row.Dispose(); rowsSize--; i--; } } m_gridPlan.Update(); m_gridPlan.BeginUpdate(); for (int i = 0; i < plansSize; i++) { CPlan plan = plans[i]; GridRow row = null; bool newData = false; if (rowsMap.ContainsKey(plan.m_id)) { row = rowsMap[plan.m_id]; } else { row = new GridRow(); row.Height = 50; selectedRow = row; m_gridPlan.AddRow(row); newData = true; } foreach (int col in columnsIndex.Keys) { GridCell cell = null; GridColumn column = columnsIndex[col]; if (newData) { if (col == 5) { GridProgressCell progressCell = new GridProgressCell(); cell = progressCell; row.AddCell(column.Index, cell); } else { cell = new GridStringCell(); if (col == 3) { cell.AllowEdit = true; } row.AddCell(column.Index, cell); } } else { cell = row.GetCell(column.Index); } switch (col) { //ID case 1: cell.SetString(plan.m_id); break; //名称 case 2: cell.SetString(plan.m_name); break; //进程 case 3: cell.SetString(plan.m_command); break; //状态 case 4: cell.SetString(plan.m_status); GridCellStyle cellStyle = new GridCellStyle(); if (plan.m_status == "启动") { cellStyle.ForeColor = CDraw.GetPriceColor(1, 2); } else if (plan.m_status == "禁用") { cellStyle.ForeColor = CDraw.GetPriceColor(2, 1); } cell.Style = cellStyle; break; //下次执行时间 case 5: GridProgressCell progressCell = cell as GridProgressCell; if (plan.m_nextTime != 0) { DateTime nowDate = DateTime.Now; long span = (long)plan.m_timeSpan * 1000 * 10000; double rate = 100 - 100 * (plan.m_nextTime - nowDate.Ticks) / span; if (rate < 0) { rate = 100 - 100 * (double)(plan.m_nextTime - nowDate.Ticks) / (plan.m_nextTime - plan.m_createTime); } progressCell.Rate = rate; } else { progressCell.Rate = 0; } cell.SetString(new DateTime(plan.m_nextTime).ToString()); break; //上次执行时间 case 6: cell.SetString(new DateTime(plan.m_lastTime).ToString()); break; //上次结果 case 7: cell.SetString(plan.m_lastResult); break; //间隔 case 8: cell.SetString(plan.m_timeSpan.ToString()); break; //创建时间 case 9: cell.SetString(new DateTime(plan.m_createTime).ToString()); break; //相关人员 case 10: cell.SetString(plan.m_member); break; } } } //修正选中行 if (selectedRow != null) { List <GridRow> selectedRows = new List <GridRow>(); selectedRows.Add(selectedRow); m_gridPlan.SelectedRows = selectedRows; } m_gridPlan.EndUpdate(); Native.Invalidate(); columnsIndex.Clear(); pids.Clear(); plans.Clear(); }
/// <summary> /// 绘制前景方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="clipRect">裁剪区域</param> public override void OnPaintForeground(CPaint paint, RECT clipRect) { int width = Width; int height = Height; if (width > 0 && height > 0) { FONT font = new FONT("SimSun", 16, false, false, false); FONT lfont = new FONT("SimSun", 14, false, false, false); long wordColor = CDraw.PCOLORS_FORECOLOR5; int top = 32, step = 20; //画买卖盘 CDraw.DrawText(paint, "卖", wordColor, font, 1, (m_lV2 ? 87 : 47)); CDraw.DrawText(paint, "盘", wordColor, font, 1, (m_lV2 ? 140 : 100)); CDraw.DrawText(paint, "买", wordColor, font, 1, (m_lV2 ? 267 : 147)); CDraw.DrawText(paint, "盘", wordColor, font, 1, (m_lV2 ? 310 : 200)); String buySellStr = "5,4,3,2,1,1,2,3,4,5"; if (m_lV2) { step = 16; buySellStr = "总卖量,10,9,8,7,6," + buySellStr + ",6,7,8,9,10,总买量"; font.m_fontSize = 14; } String[] buySellStrs = buySellStr.Split(','); int strsSize = buySellStrs.Length; for (int i = 0; i < strsSize; i++) { CDraw.DrawText(paint, buySellStrs[i], wordColor, font, 25, top); top += step; } font.m_fontSize = 16; top = m_lV2 ? 390 : 232; CDraw.DrawText(paint, "最新", wordColor, font, 1, top); CDraw.DrawText(paint, "升跌", wordColor, font, 1, top + 20); CDraw.DrawText(paint, "幅度", wordColor, font, 1, top + 40); CDraw.DrawText(paint, "总手", wordColor, font, 1, top + 60); CDraw.DrawText(paint, "涨停", wordColor, font, 1, top + 80); CDraw.DrawText(paint, "外盘", wordColor, font, 1, top + 100); CDraw.DrawText(paint, "开盘", wordColor, font, 110, top); CDraw.DrawText(paint, "最高", wordColor, font, 110, top + 20); CDraw.DrawText(paint, "最低", wordColor, font, 110, top + 40); CDraw.DrawText(paint, "换手", wordColor, font, 110, top + 60); CDraw.DrawText(paint, "跌停", wordColor, font, 110, top + 80); CDraw.DrawText(paint, "内盘", wordColor, font, 110, top + 100); font.m_bold = true; //画股票代码 long yellowColor = COLOR.ARGB(255, 255, 80); if (m_latestData.m_code != null && m_latestData.m_code.Length > 0) { double close = m_latestData.m_close, open = m_latestData.m_open, high = m_latestData.m_high, low = m_latestData.m_low, lastClose = m_latestData.m_lastClose; if (close == 0) { if (m_latestData.m_buyPrice1 > 0) { close = m_latestData.m_buyPrice1; open = m_latestData.m_buyPrice1; high = m_latestData.m_buyPrice1; low = m_latestData.m_buyPrice1; } else if (m_latestData.m_sellPrice1 > 0) { close = m_latestData.m_sellPrice1; open = m_latestData.m_sellPrice1; high = m_latestData.m_sellPrice1; low = m_latestData.m_sellPrice1; } } if (lastClose == 0) { lastClose = close; } List <double> plist = new List <double>(); List <double> vlist = new List <double>(); if (m_lV2) { plist.Add(m_latestData.m_sellPrice10); plist.Add(m_latestData.m_sellPrice9); plist.Add(m_latestData.m_sellPrice8); plist.Add(m_latestData.m_sellPrice7); plist.Add(m_latestData.m_sellPrice6); vlist.Add(m_latestData.m_sellVolume10); vlist.Add(m_latestData.m_sellVolume9); vlist.Add(m_latestData.m_sellVolume8); vlist.Add(m_latestData.m_sellVolume7); vlist.Add(m_latestData.m_sellVolume6); } plist.Add(m_latestData.m_sellPrice5); plist.Add(m_latestData.m_sellPrice4); plist.Add(m_latestData.m_sellPrice3); plist.Add(m_latestData.m_sellPrice2); plist.Add(m_latestData.m_sellPrice1); vlist.Add(m_latestData.m_sellVolume5); vlist.Add(m_latestData.m_sellVolume4); vlist.Add(m_latestData.m_sellVolume3); vlist.Add(m_latestData.m_sellVolume2); vlist.Add(m_latestData.m_sellVolume1); plist.Add(m_latestData.m_buyPrice1); plist.Add(m_latestData.m_buyPrice2); plist.Add(m_latestData.m_buyPrice3); plist.Add(m_latestData.m_buyPrice4); plist.Add(m_latestData.m_buyPrice5); vlist.Add(m_latestData.m_buyVolume1); vlist.Add(m_latestData.m_buyVolume2); vlist.Add(m_latestData.m_buyVolume3); vlist.Add(m_latestData.m_buyVolume4); vlist.Add(m_latestData.m_buyVolume5); if (m_lV2) { plist.Add(m_latestData.m_buyPrice6); plist.Add(m_latestData.m_buyPrice7); plist.Add(m_latestData.m_buyPrice8); plist.Add(m_latestData.m_buyPrice9); plist.Add(m_latestData.m_buyPrice10); vlist.Add(m_latestData.m_buyVolume6); vlist.Add(m_latestData.m_buyVolume7); vlist.Add(m_latestData.m_buyVolume8); vlist.Add(m_latestData.m_buyVolume9); vlist.Add(m_latestData.m_buyVolume10); } long color = 0; double max = Max(vlist); font.m_fontSize = m_lV2 ? 14 : 16; if (max > 0) { //绘制买卖盘 int pLength = plist.Count; top = 32; if (m_lV2) { color = CDraw.GetPriceColor(m_latestData.m_avgSellPrice, lastClose); CDraw.DrawUnderLineNum(paint, m_latestData.m_avgSellPrice, m_digit, font, color, false, 80, top); color = CDraw.GetPriceColor(0, m_latestData.m_allSellVol); CDraw.DrawUnderLineNum(paint, m_latestData.m_allSellVol, 0, font, yellowColor, false, 130, top); top += step; } for (int i = 0; i < pLength; i++) { color = CDraw.GetPriceColor(plist[i], lastClose); CDraw.DrawUnderLineNum(paint, plist[i], m_digit, font, color, true, m_lV2 ? 80 : 60, top); CDraw.DrawUnderLineNum(paint, vlist[i], 0, font, yellowColor, false, m_lV2 ? 130 : 110, top); paint.FillRect(color, new RECT(width - (int)(vlist[i] / max * 50), top + step / 2 - 2, width, top + step / 2 + 2)); top += step; } if (m_lV2) { color = CDraw.GetPriceColor(m_latestData.m_avgBuyPrice, lastClose); CDraw.DrawUnderLineNum(paint, m_latestData.m_avgBuyPrice, m_digit, font, color, false, 80, top); color = CDraw.GetPriceColor(m_latestData.m_allBuyVol, 0); CDraw.DrawUnderLineNum(paint, m_latestData.m_allBuyVol, 0, font, yellowColor, false, 130, top); top += step; } } vlist.Clear(); plist.Clear(); top = m_lV2 ? 390 : 232; //成交 color = CDraw.GetPriceColor(close, lastClose); CDraw.DrawUnderLineNum(paint, close, m_digit, font, color, true, 45, top); //升跌 double sub = 0; if (close == 0) { sub = m_latestData.m_buyPrice1 - lastClose; double rate = 100 * (m_latestData.m_buyPrice1 - lastClose) / lastClose; int pleft = CDraw.DrawUnderLineNum(paint, rate, 2, font, color, false, 45, top + 40); CDraw.DrawText(paint, "%", color, font, pleft + 47, top + 40); } else { sub = close - m_latestData.m_lastClose; double rate = 100 * (close - lastClose) / lastClose; int pleft = CDraw.DrawUnderLineNum(paint, rate, 2, font, color, false, 45, top + 40); CDraw.DrawText(paint, "%", color, font, pleft + 47, top + 40); } CDraw.DrawUnderLineNum(paint, sub, m_digit, font, color, false, 45, top + 20); double volume = m_latestData.m_volume / 100; String unit = ""; if (volume > 100000000) { volume /= 100000000; unit = "亿"; } else if (volume > 10000) { volume /= 10000; unit = "万"; } //总手 int cleft = CDraw.DrawUnderLineNum(paint, volume, unit.Length > 0 ? m_digit : 0, font, yellowColor, true, 45, top + 60); if (unit.Length > 0) { CDraw.DrawText(paint, unit, yellowColor, font, cleft + 47, top + 60); } //换手 double turnoverRate = m_latestData.m_turnoverRate; cleft = CDraw.DrawUnderLineNum(paint, turnoverRate, 2, font, yellowColor, true, 155, top + 60); if (turnoverRate > 0) { CDraw.DrawText(paint, "%", yellowColor, font, cleft + 157, top + 60); } //开盘 color = CDraw.GetPriceColor(open, lastClose); CDraw.DrawUnderLineNum(paint, open, m_digit, font, color, true, 155, top); //最高 color = CDraw.GetPriceColor(high, lastClose); CDraw.DrawUnderLineNum(paint, high, m_digit, font, color, true, 155, top + 20); //最低 color = CDraw.GetPriceColor(low, lastClose); CDraw.DrawUnderLineNum(paint, low, m_digit, font, color, true, 155, top + 40); //涨停 double upPrice = lastClose * 1.1; if (m_securityName != null && m_securityName.Length > 0) { if (m_securityName.StartsWith("ST") || m_securityName.StartsWith("*ST")) { upPrice = lastClose * 1.05; } } CDraw.DrawUnderLineNum(paint, upPrice, m_digit, font, CDraw.PCOLORS_UPCOLOR, true, 45, top + 80); //跌停 double downPrice = lastClose * 0.9; if (m_securityName != null && m_securityName.Length > 0) { if (m_securityName.StartsWith("ST") || m_securityName.StartsWith("*ST")) { downPrice = lastClose * 0.95; } } CDraw.DrawUnderLineNum(paint, downPrice, m_digit, font, CDraw.PCOLORS_DOWNCOLOR, true, 155, top + 80); //外盘 double outerVol = m_latestData.m_outerVol; unit = ""; if (outerVol > 100000000) { outerVol /= 100000000; unit = "亿"; } else if (outerVol > 10000) { outerVol /= 10000; unit = "万"; } cleft = CDraw.DrawUnderLineNum(paint, outerVol, unit.Length > 0 ? m_digit : 0, font, CDraw.PCOLORS_UPCOLOR, false, 45, top + 100); if (unit.Length > 0) { CDraw.DrawText(paint, unit, CDraw.PCOLORS_UPCOLOR, font, cleft + 47, top + 100); } unit = ""; double innerVol = m_latestData.m_innerVol; if (innerVol > 100000000) { innerVol /= 100000000; unit = "亿"; } else if (innerVol > 10000) { innerVol /= 10000; unit = "万"; } //内盘 cleft = CDraw.DrawUnderLineNum(paint, innerVol, unit.Length > 0 ? m_digit : 0, font, CDraw.PCOLORS_DOWNCOLOR, true, 155, top + 100); if (unit.Length > 0) { CDraw.DrawText(paint, unit, CDraw.PCOLORS_DOWNCOLOR, font, cleft + 157, top + 100); } } font.m_bold = false; font.m_fontSize = 20; //股票代码 if (m_securityCode != null && m_securityCode.Length > 0) { CDraw.DrawText(paint, m_securityCode, CDraw.PCOLORS_FORECOLOR3, font, 2, 4); } //股票名称 if (m_securityName != null && m_securityName.Length > 0) { CDraw.DrawText(paint, m_securityName, yellowColor, font, 100, 4); } //画边框 long frameColor = CDraw.PCOLORS_LINECOLOR4; paint.DrawLine(frameColor, 1, 0, 0, 0, 0, height); paint.DrawLine(frameColor, 1, 0, 0, 30, width, 30); paint.DrawLine(frameColor, 1, 0, 24, 30, 24, top - 2); paint.DrawLine(frameColor, 1, 0, 0, m_lV2 ? 208 : 130, width, m_lV2 ? 208 : 130); paint.DrawLine(frameColor, 1, 0, 0, top - 2, width, top - 2); paint.DrawLine(frameColor, 1, 0, width, 0, width, height); paint.DrawLine(frameColor, 1, 0, 0, top + 120, width, top + 120); } }
/// <summary> /// 获取颜色 /// </summary> /// <param name="dwPenColor">输入颜色</param> /// <returns>输出颜色</returns> public override long GetColor(long dwPenColor) { return(CDraw.GetWhiteColor(dwPenColor)); }
/// <summary> /// 重绘背景方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="clipRect">裁剪区域</param> public override void OnPaintBackground(CPaint paint, RECT clipRect) { int width = Width; int height = Height; if (width > 0 && height > 0) { ChartA chart = m_chart.Chart; //十字线出现时进行绘制 if (chart.ShowCrossLine) { CTable dataSource = chart.DataSource; //获取鼠标停留索引 int crossStopIndex = chart.CrossStopIndex; if (dataSource.RowsCount > 0) { if (crossStopIndex < 0) { crossStopIndex = chart.FirstVisibleIndex; } if (crossStopIndex > chart.LastVisibleIndex) { crossStopIndex = chart.LastVisibleIndex; } } else { crossStopIndex = -1; } //获取K线和成交量 RECT rectangle = new RECT(0, 0, width, height); long win32Color = COLOR.EMPTY; paint.FillRect(GetPaintingBackColor(), rectangle); paint.DrawRect(GetPaintingBorderColor(), 1, 0, rectangle); //画关闭按钮 long lineColor = CDraw.PCOLORS_LINECOLOR; paint.DrawLine(lineColor, 2, 0, width - 6, 4, width - 14, 12); paint.DrawLine(lineColor, 2, 0, width - 6, 12, width - 14, 4); //创建字体 FONT font = new FONT("SimSun", 14, false, false, false); FONT lfont = new FONT("Arial", 12, false, false, false); FONT nfont = new FONT("Arial", 14, true, false, false); //画日期 CDraw.DrawText(paint, "时 间", CDraw.PCOLORS_FORECOLOR4, font, rectangle.left + 25, rectangle.top + 2); DateTime date = DateTime.Now; if (crossStopIndex >= 0) { double dateNum = dataSource.GetXValue(crossStopIndex); if (dateNum != 0) { date = CStr.ConvertNumToDate(dateNum); } String dateStr = ""; int cycle = m_chart.Cycle; if (cycle <= 1) { dateStr = date.ToString("hh:mm"); } else if (cycle >= 5 && cycle <= 60) { dateStr = date.ToString("MM-dd hh:mm"); } else { dateStr = date.ToString("yyyy-MM-dd"); } SIZE dtSize = paint.TextSize(dateStr, lfont); CDraw.DrawText(paint, dateStr, CDraw.PCOLORS_FORECOLOR3, lfont, rectangle.left + width / 2 - dtSize.cx / 2, rectangle.top + 20); //获取值 double close = 0, high = 0, low = 0, open = 0, amount = 0; if (crossStopIndex >= 0) { close = dataSource.Get2(crossStopIndex, KeyFields.CLOSE_INDEX); high = dataSource.Get2(crossStopIndex, KeyFields.HIGH_INDEX); low = dataSource.Get2(crossStopIndex, KeyFields.LOW_INDEX); open = dataSource.Get2(crossStopIndex, KeyFields.OPEN_INDEX); amount = dataSource.Get2(crossStopIndex, KeyFields.AMOUNT_INDEX); } if (double.IsNaN(close)) { close = 0; } if (double.IsNaN(high)) { high = 0; } if (double.IsNaN(low)) { low = 0; } if (double.IsNaN(open)) { open = 0; } if (double.IsNaN(amount)) { amount = 0; } double rate = 1; double lastClose = 0; if (crossStopIndex > 1) { lastClose = dataSource.Get2(crossStopIndex - 1, KeyFields.CLOSE_INDEX); if (cycle == 0) { lastClose = m_chart.LatestData.m_lastClose; } if (!double.IsNaN(lastClose)) { if (lastClose != 0) { rate = (close - lastClose) / lastClose; } } } //开盘价 String openStr = double.IsNaN(open) ? "" : CStr.GetValueByDigit(open, m_digit).ToString(); SIZE tSize = paint.TextSize(openStr, nfont); CDraw.DrawText(paint, openStr, CDraw.GetPriceColor(open, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 60); //最高价 String highStr = double.IsNaN(high) ? "" : CStr.GetValueByDigit(high, m_digit).ToString(); tSize = paint.TextSize(highStr, nfont); CDraw.DrawText(paint, highStr, CDraw.GetPriceColor(high, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 100); //最低价 String lowStr = double.IsNaN(low) ? "" : CStr.GetValueByDigit(low, m_digit).ToString(); tSize = paint.TextSize(lowStr, nfont); CDraw.DrawText(paint, lowStr, CDraw.GetPriceColor(low, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 140); //最低价 String closeStr = double.IsNaN(close) ? "" : CStr.GetValueByDigit(close, m_digit).ToString(); tSize = paint.TextSize(closeStr, nfont); CDraw.DrawText(paint, closeStr, CDraw.GetPriceColor(close, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 180); //成交量 String unit = ""; if (amount > 100000000) { amount /= 100000000; unit = "亿"; } else if (amount > 10000) { amount /= 10000; unit = "万"; } String amountStr = CStr.GetValueByDigit(amount, 2) + unit; tSize = paint.TextSize(amountStr, lfont); CDraw.DrawText(paint, amountStr, CDraw.PCOLORS_FORECOLOR3, lfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 220); //涨幅 String rangeStr = double.IsNaN(rate) ? "0.00%" : rate.ToString("0.00%"); tSize = paint.TextSize(rangeStr, nfont); CDraw.DrawText(paint, rangeStr, CDraw.GetPriceColor(close, lastClose), lfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 260); } long whiteColor = CDraw.PCOLORS_FORECOLOR4; CDraw.DrawText(paint, "开 盘", whiteColor, font, rectangle.left + 25, rectangle.top + 40); CDraw.DrawText(paint, "最 高", whiteColor, font, rectangle.left + 25, rectangle.top + 80); CDraw.DrawText(paint, "最 低", whiteColor, font, rectangle.left + 25, rectangle.top + 120); CDraw.DrawText(paint, "收 盘", whiteColor, font, rectangle.left + 25, rectangle.top + 160); CDraw.DrawText(paint, "金 额", whiteColor, font, rectangle.left + 25, rectangle.top + 200); CDraw.DrawText(paint, "涨 幅", whiteColor, font, rectangle.left + 25, rectangle.top + 240); } } }