private void gridTask_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } if (this.gridTask.Columns[e.ColumnIndex].Name.StartsWith("任务")) { OrderTaskResult result = this.gridTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value as OrderTaskResult; if (result != null) { if (result.IsFinish) { e.CellStyle.BackColor = Color.Green; } else if (result.IsOrder) { e.CellStyle.BackColor = Color.Yellow; } else { e.CellStyle.BackColor = Color.White; } } } }
/// <summary> /// 创建任务列表。 /// </summary> /// <returns></returns> private DataTable CreateTaskTable(string tableName, ArbitrageTaskGroup taskGroup) { DataTable table = new DataTable(); table.TableName = tableName; table.Columns.Add("Direction", typeof(string)); table.Columns.Add("Instrument", typeof(USeInstrument)); if (taskGroup != null && taskGroup.TaskCount > 0) { for (int i = 0; i < taskGroup.TaskCount; i++) { table.Columns.Add(string.Format("任务{0}", (i + 1)), typeof(OrderTaskResult)); } } DataRow buyRow = table.NewRow(); buyRow["Direction"] = "买入"; buyRow["Instrument"] = taskGroup.BuyInstrument; DataRow sellRow = table.NewRow(); sellRow["Direction"] = "卖出"; sellRow["Instrument"] = taskGroup.SellInstrument; foreach (DataColumn column in table.Columns) { if (column.ColumnName.StartsWith("任务") == false) { continue; } buyRow[column] = new OrderTaskResult(); sellRow[column] = new OrderTaskResult(); } if (taskGroup.PreferentialSide == USeOrderSide.Buy) { table.Rows.Add(buyRow); table.Rows.Add(sellRow); } else if (taskGroup.PreferentialSide == USeOrderSide.Sell) { table.Rows.Add(sellRow); table.Rows.Add(buyRow); } else { Debug.Assert(false); } return(table); }
private void gridTask_CellMouseEnter(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex < 0 || e.RowIndex < 0) { return; } DataGridViewCell cell = this.gridTask.Rows[e.RowIndex].Cells[e.ColumnIndex]; OrderTaskResult result = cell.Value as OrderTaskResult; if (result != null) { StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("计划委托: {0}", result.PlanOrderQty)); sb.AppendLine(string.Format(" 委托量: {0}", result.OrderQty)); sb.AppendLine(string.Format(" 成交量: {0}", result.TradeQty)); sb.Append(string.Format("成交均价: {0}", result.AvgTradePrice)); cell.ToolTipText = sb.ToString(); } }
private void FillTaskTable(DataTable table, ArbitrageTaskGroup taskGroup) { if (taskGroup == null) { //Debug.Assert(false); return; } Debug.Assert(taskGroup.TaskCount == table.Columns.Count - 2); Debug.Assert(table.Rows.Count == 2); DataRow firstRow = table.Rows[0]; DataRow secondRow = table.Rows[1]; foreach (ArbitrageTask task in taskGroup.TaskList) { string cloumnName = string.Format("任务{0}", task.TaskId); { OrderTaskResult firstResult = new OrderTaskResult(); firstResult.PlanOrderQty = task.FirstSubTask.PlanOrderQty; firstResult.OrderQty = task.FirstSubTask.OrderQty; firstResult.TradeQty = task.FirstSubTask.TradeQty; firstResult.AvgTradePrice = task.FirstSubTask.TradeAvgPrice; firstRow[cloumnName] = firstResult; } { OrderTaskResult secondResult = new OrderTaskResult(); secondResult.PlanOrderQty = task.SecondSubTask.PlanOrderQty; secondResult.OrderQty = task.SecondSubTask.OrderQty; secondResult.TradeQty = task.SecondSubTask.TradeQty; secondResult.AvgTradePrice = task.SecondSubTask.TradeAvgPrice; secondRow[cloumnName] = secondResult; } } }